简体   繁体   中英

django.db.utils.OperationalError: (1050, "Table 'profiles_category' already exists")

I am trying to host my website using FileZilla and PuTTY. For that, I have added the code in FileZilla remote site and I have created a database named jobs using following commands in PuTTY app.

sudo mysql -u root #For Maria DB
CREATE DATABASE jobs;
GRANT ALL PRIVILEGES ON jobs.*TO 'hello'@'localhost';
flush privileges;
exit

Then python3 manage.py makemigrations command is executed and after that when I executed the python3 manage.py migrate command I got an error like this.

django.db.utils.OperationalError: (1050, "Table 'profiles_category' already exists")

Here the table profiles_category is not already existed.

models.py

class Category(models.Model):
   name = models.CharField(max_length=40)

   def __str__(self):
       return self.name

class CategoryJob(models.Model):
   category = models.ForeignKey(Category, on_delete=models.CASCADE)
   name = models.CharField(max_length=40)

   def __str__(self):
       return self.name

Can anyone suggest a solution for this?

just delete db.sqlite.sql file,

delete also: all migrations and cache

THEN

python manage.py migrate

python manage.py makemigrations

finally:

python manage.py migrate --run-syncdb

I had / have a similar problem - if you that it might work for you also.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM