Reputation: 515
I am getting error like django.db.utils.OperationalError: (1050, "Table 'someTable' already exists")
I want to know reason for getting this type error.
I ran the following commands on termial
1. python manage.py makemigration app
2. python manage.py migrate app
When ran migrate then getting the above error. I solve my problem by running
python manage.py migrate --fake app
But I want to know why I am getting this error, and how --fake app
solve my problem. Thanks
Upvotes: 3
Views: 4433
Reputation: 81
I had the same problem. I was using the MySQL database.
With SQLite, you will need to delete the SQLite.db
All I did when using MySQL as database to handle this was...
python manage.py makemigrations
mysql> drop database [database name];
mysql> create database [database name];
python manage.py migrate --run-syncdb
commandUpvotes: 0
Reputation: 77912
The table 'someTable' already exists in your database - either because it's been created by a previous call to ./manage.py syncdb
or because you created it manually (or you used South before and are switching to Django >= 1.7) - and you obviously didn't have any existing django (non-south) migration, so makemigration
thinks the table has to be created (rightly so sonce that will indeed be the case for someone that install your app from scratch).
Using the --fake
flag tells migrate
command to just record the migration has having been applied without effectively applying it, and that's the whole point of this flag: when your app has already been installed (db tables etc) without migrations and you want to start using migrations.
Upvotes: 3
Reputation: 7596
This problem means that someTable
was created without Django migrations or record about migrations in django_migrations
was deleted. --fake
adds record about migrations in django_migrations
without applying actual migrations.
Record in django_migrations
contains information about migration: app label, migration name and date when migrations was applied.
Upvotes: 2