0

I am changing from a profile model setup, to extending the User model. I am trying to get my South migrations set up according to this guide. I have a few other models that reference the User model, and so when I auto-generate my schema migration I get lines along the lines of:

db.alter_column(u'app_model', 'user', 
  self.gf('django.db.models.fields.related.ForeignKey')(to=orm['app.user']))

The problem is these migrations cause South to break when I try and migrate:

FATAL ERROR - The following SQL query failed: INSERT INTO "_south_new_app_model" () SELECT  FROM "app_model";
The error was: near ")": syntax error
 ! Error found during real run of migration! Aborting.

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

! You *might* be able to recover with:
 ! The South developers regret this has happened, and would
 ! like to gently persuade you to consider a slightly
 ! easier-to-deal-with DBMS (one that supports DDL transactions)
 ! NOTE: The error which caused the migration to fail is further up.
Error in migration: app:0018_auto__chg_field_model_user.py
DatabaseError: near ")": syntax error

Note: this is a migration created with ./manage.py schemamigration app --auto. I haven't edited it.

The thing is, do I care? The type of the reference stored in the database is the same, and I've done the step of renaming the table. Everything seems to continue working if I remove the alter_table lines from the migration. Is this a terrible, terrible idea, or is it ok?

Community
  • 1
  • 1
fredley
  • 32,953
  • 42
  • 145
  • 236
  • What database engine are you using? And I think yes, you should always care when there are errors. Maybe it works now but later there star appearing bugs and you don't even remember you ignored an error in the past :) – Paulo Bu Apr 29 '13 at 15:31
  • @Paulo This is just on a test database which is running sqlite3 (which I'm guessing is part of the problem). My production database is MySQL. I could test with another mysql instance, but I'd rather avoid it if possible. – fredley Apr 29 '13 at 15:55

1 Answers1

1

Sqlite3 is the problem. As you may see here, sqlite3 support just a limited subset of alter table operations so that is causing South to fail the migration. If you need to do this you'll have to port the test database to another engine which supports alter table. Which I recommend, sometimes migrations can be tricky and you may think it's working but is always better to test it.

If you think is working ok, so go on and just ignore the error, but caution, it may be working now but maybe the migrations didn't succeed and later you'll find strange database related bugs in your development environment.

Paulo Bu
  • 29,294
  • 6
  • 74
  • 73