6

I changed my models and made migrations. Then i changed my models another one time and when try python manage.py migrate i get error:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions, shop
Running migrations:
  Applying shop.0004_auto_20180128_1331...Traceback (most recent call last):
  File "/home/morilon/dj/intshop/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 83, in _execute
    return self.cursor.execute(sql)
  File "/home/morilon/dj/intshop/venv/lib/python3.6/site-packages/django/db/backends/sqlite3/base.py", line 301, in execute
    return Database.Cursor.execute(self, query)
sqlite3.OperationalError: table "shop_brand" already exists

So my question is - how can i delete table "shop_brand"??? I already tried flush and sqlflush but that only delete data from table but not actually table "shop_brand".

I use django 2.0.1 and python 3.6

2
  • Check out this Commented Jan 28, 2018 at 16:57
  • Just delete all files is an option but i want know how to delete only one tablet in database. Commented Jan 28, 2018 at 17:38

1 Answer 1

26

Use the dbshell command

python manage.py dbshell

then while in the shell, depending on what database you are using, you type the command to show tables to identify the table you want to drop.

For instance, for sqlite, you would use

.tables

still in the shell, you can use SQL command to drop the table

DROP TABLE shop_brand;
Sign up to request clarification or add additional context in comments.

6 Comments

I tried but CommandError: You appear not to have the 'sqlite3' program installed or on your path.
or install sqlite3 sudo apt-get install sqlite3
Ok i will try. I just thought i can deal with it only with Django.
I CAN NOT restore the table after doing this by makemigrations or migrate
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.