Forums

Migrating from SQLite to MySQL

I have been using SQLite for some time but my site gets slow every day so I migrated to MySQL. But I ran into error. "BLOG/TEXT column 'slug' used in key specification without a key length " Then I added a key length to my slug still it doesn't solve the problem. Pls how can I fix this.

this is the image url for the console error https://ibb.co/NLSZ573

The accepted answer for this stack overflow post has some options.

Thank you for your quick response but to be honest i'm new to django and mysql. please can any body give a detail explanation of how i can resolve this. I followed the link provided above and it was complicating

It looks like a general programming issue and our forums are dedicated to PythonAnywhere technical issues. We could try to help you if you provide us more details, like what exactly you were doing and what didn't work for you.

This is what I meant I am migrating from SQLite to MySQL I took these steps as discussed here AND here 1. Use dumpdata to get a dump of the database into a file 2.Change the database settings to point to a MySQL ones. 3.Run the migrate management command to get the database tables set up. 4.Run loaddata to get the previously-installed data into it. So i ran into erros that BLOG/TEXT column 'slug' key specification without key length. this is image link https://ibb.co/NLSZ573 I have seen some similar problems on stackovetflow but i dont know the approach in fixing it. so please can you guide me on how to fix it?

You mentioned earlier that you added a key length to your slug. What were the exact steps that you did to do that?

.

class Past_Question(models.Model):
    author = models.ForeignKey(User,on_delete=models.CASCADE)
    read_min = models.CharField(max_length=30,default='30 mins estimated study time')
    tag = models.CharField(max_length=300,default='Past_Question')
    title = models.TextField(null=True,blank=False)
    topic = models.TextField(null=True,blank=True)
    keyword = models.TextField(blank=True,null=True)
    table_of_content = RichTextUploadingField(blank=False)
    content = RichTextUploadingField(blank=False)
    learning_objective = RichTextUploadingField(blank=True)
    image = models.ImageField(blank=True, null=True)
    date_added = models.DateTimeField(default=datetime.now,blank=True)
    slug = models.SlugField(max_length=250,blank=True,unique=True)

def __str__(self):
    return self.title

def get_absolute_url(self):
    return reverse ("past_detail",kwargs={'slug':self.slug})

def save(self, *args, **kwargs):  # new
    if not self.slug:
        self.slug = slugify(self.title)
    return super().save(*args, **kwargs)

that is models.py above. with slug and key length

try removing the unique=True from the slug definition.

when the error pop up , i removed the unique key and also added the key key length before starting a new topic here . the error still comes up .

Did you migrate the database after making the changes?

Yes I did migrations , that Is when I notice the error , please I need special attention to these. My website is getting slow every day because SQLite can't handle 100's of visitors at once making it load very slow. Please I will appreciate if this problems could be solved

The migrations can not be completed because the BLOB/TEXT 'slug' error with key without specification length will pop up. Please I really need special attention to these. Please.

No. I mean did you run manage.py migrate after making that changes to the models? Also, perhaps you MySQL database is in a weird state from previous attempts. Try it in a new database.

ok can i delete the msql in site-packeges if the database is messed up , will another one be initiated? picture:https://ibb.co/yV7pzt3

I don't think @Glenn was relating to mysql Python package -- rather to an actual MySQL database. You can manage your databases on the Databases page.

yes i can manage my databases on the Databases Page so could you be of help to my problems as described above @pafk

I see that Glenn asked if you'd run the migrate command after you made your change to your models file; did you also run the makemigrations command before doing the migrate?

I did all that still the same problems keeps coming.I created a demo database and back up the database then i have to wipe out every thing on the sql3 data base then i did makemigrations and migrate , it worked well but right now i'm facing another error with primary key and user auth when installing the the demo database. Still working hard on how to fix it

What is the error?