1

I added a column to my models.py and it was giving me issues. On the road to trying to solve the problems I've done a couple things.

  1. Dropped the table: ./manage.py sqlclear app | ./manage.py dbshell
  2. Tried to "reset" the schema: ./manage.py schemamigration app --initial
  3. Tried to migrate: ./manage.py migrate app

After doing all these things, I get this error after trying to migrate:

FATAL ERROR - The following SQL query failed: CREATE TABLE "projects_project" ("id" integer NOT NULL PRIMARY KEY)
The error was: table "projects_project" already exists

Question: How do I repair my database? I don't care about any of the data in the db.

Edit:

One of the related posts took me to this link Django South - table already exists . Apparently if you fake the migration all is well.

./manage.py migrate myapp --fake

I'm still unsure of all the reprocussions of this but I guess thats what docs are for.

Community
  • 1
  • 1
Colton Allen
  • 2,940
  • 2
  • 23
  • 33

1 Answers1

0

Welll, the error points it out pretty clearly:

table "projects_project" already exists

You can either do it the quick and dirty way and drop the table. In that case log into your DMBS. If it's MySQL, you'll just open the terminal and typ:

mysql -u root -p YOURPASSWORD

Then select the database:

use your_database;

Finally, drop the table:

DROP TABLE projects_project;

You should be able to migrate now. The elegant way would be to undo the migration. But every framework has it's own way to do that. You need to figure that out first - or give us more information.

Andy M
  • 41
  • 1
  • 5
  • I'm using SQLite. The `./manage.py sqlclear` does just what you said. It drops the tables. I dropped them, confirmed they did not exist, and then went on to step two. I edited my post. Apparently, faking the migration solves the issue. I don't know why exactly but thats what docs are for. Thanks for the answer! It will be handy when I use MySQL again. – Colton Allen Jul 02 '14 at 16:25