Jayhad
Jayhad

Reputation: 53

"Operational Error" when running coverage test

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

Answers (2)

Kashyap KN
Kashyap KN

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.

  1. First go to the migrations directory like myapp/migrations/
  2. 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=[
    
  3. 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.

  4. 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

DimoMohit
DimoMohit

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

Related Questions