user1811889
user1811889

Reputation: 11

Django South added model to admin but gives DatabaseError

I've just started using south with an existing app, and after adding new models to the db, I can view the models in the admin, but when clicking on them to view the model details an error

I try to do the south equivalent of syncdb:

python manage.py schemamigration directory --initial

python manage.py migrate directory

where directory is the app name.

So when i try and view the model in admin I get the following:

Exception Type: DatabaseError

Exception Value: (1146, "Table 'omada.directory_drift' doesn't exist")

where Drift is the model I added to models.py, then registered in admin.py - omada is the site name.

Further Information:

Traceback from the django site ends with:

File "/usr/local/lib/python2.7/dist-packages/django/db/backends/mysql/base.py" in execute


  114.             return self.cursor.execute(query, args) File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b5-py2.7-linux-i686.egg/MySQLdb/cursors.py" in execute
  201.             self.errorhandler(self, exc, value) File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b5-py2.7-linux-i686.egg/MySQLdb/connections.py" in defaulterrorhandler
  36.     raise errorclass, errorvalue

When executing

python manage.py migrate directory

I get an error that starts with:

FATAL ERROR - The following SQL query failed: CREATE TABLE `directory_building`
 ! Since you have a database that does not support running
 ! schema-altering statements in transactions, we have had
 ! to leave it in an interim state between migrations.

which doesn't sound very promising :S, and ends with:

  File "/usr/local/lib/python2.7/dist-packages/MySQL_python-1.2.4b5-py2.7-linux-i686.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler                
    raise errorclass, errorvalue
django.db.utils.DatabaseError: (1050, "Table 'directory_building' already exists")

Thanks in advance to everyone who takes the time to read this and offer help!

Upvotes: 1

Views: 542

Answers (1)

RickyA
RickyA

Reputation: 16029

You may find this guide useful.

Since you are only starting with South I would advice to start all over:

  1. Drop your south table (south_migrationhistory) from your database

  2. Delete the migrations from the app.migrations folder

  3. Follow the guide

It is quite easy to get South in a bad state so you just need to get some experience with it. You however can't live without it as your projects grow in size.

Upvotes: 1

Related Questions