I can't figure out what to do to avoid this error whenever I try to make a migration using South in one of my Django projects:
ERROR:
Running migrations for askbot:
- Migrating forwards to 0006_auto__del_field_tagplus_tag_ptr__add_field_tagplus_id__add_field_tagpl.
askbot:0006_auto__del_field_tagplus_tag_ptr__add_field_tagplus_id__add_field_tagpl
FATAL ERROR - The following SQL query failed: ALTER TABLE "tagplus" ADD COLUMN "id" serial NOT >NULL PRIMARY KEY DEFAULT -1; The error was: multiple default values specified for column "id" of table "tagplus"
Error in migration: >askbot:0006_auto__del_field_tagplus_tag_ptr__add_field_tagplus_id__add_field_tagpl DatabaseError: multiple default values specified for column "id" of table "tagplus"
MIGRATION FILE 0006 CODE (Partial):
class Migration(SchemaMigration):
def forwards(self, orm):
# Deleting field 'TagPlus.tag_ptr'
db.delete_column(u'tagplus', u'tag_ptr_id')
# Adding field 'TagPlus.id'
db.add_column(u'tagplus', u'id',
self.gf('django.db.models.fields.AutoField')(default=0, primary_key=True),
keep_default=False)
# Adding field 'TagPlus.name'
db.add_column(u'tagplus', 'name',
self.gf('django.db.models.fields.CharField')(default=0, unique=True, max_length=255),
keep_default=False)
Thanks!
EDIT:
I Guess the error has something to do with this choice I was prompted while creating the migration file.
? The field 'TagPlus.tag_ptr' does not have a default specified, yet is NOT NULL.
? Since you are removing this field, you MUST specify a default
? value to use for existing rows. Would you like to:
? 1. Quit now.
? 2. Specify a one-off value to use for existing columns now
? 3. Disable the backwards migration by raising an exception; you can edit the migration to fix it later
? Please select a choice:
I selected 'specify one-off value' and I set this value to 0
You are anyways saying keep_default=False
. So remove that default=0
from your code
db.add_column(u'tagplus', u'id',
self.gf('django.db.models.fields.AutoField')(primary_key=True),
keep_default=False)
Per SQL it should be (remove the NOT NULL
)
ALTER TABLE tagplus ADD COLUMN id serial PRIMARY KEY
See this document which explains the reason behind this error http://www.postgresql.org/docs/8.3/interactive/datatype-numeric.html#DATATYPE-SERIAL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With