Reputation: 53
Hi I got a problem when running a coverage test in my django project, an operational error saying that a database already exists, I tried using fake migration
python manage.py migrate <appname> --fake
This is the error message I see
File "c:\users\ziad hossain\appdata\local\programs\python\python37\lib\site-packages\django\db\backends\sqlite3\base.py", line 381, in execute
return Database.Cursor.execute(self, query)
django.db.utils.OperationalError: table "driver_driver_customer" already exists
Upvotes: 0
Views: 130
Reputation: 419
Best solution for the above would be to go through the migrations folder and check why is django trying to create a Model that already exits.
Do a grep on your table name on those .py files. Check if anything like this is present.
migrations.CreateModel(
name='driver_driver_customer',
fields=[
Remove the file containing the above (including the respective .pyc file). Now do makemigrations and check if it showing something like
- Create Table driver_driver_customer
if not apply migrations.
If the same issues persists again, take a backup of the migrations folder, and remove all the files except __init__.py and __init__.pyc. Now apply migrations it should work.
Upvotes: 0
Reputation: 722
If you have the table created in the database, you can run python manage.py migrate --fake <appname>
before using this I would suggest to check the Django version . You may use python manage.py migrate --fake-initial
. For version <= 1.8 refer https://docs.djangoproject.com/en/1.8/topics/migrations/ for greater versions you will find --fake missing in documents https://docs.djangoproject.com/en/2.2/topics/migrations/.
Upvotes: 3