Ticket #1119 (new defect)
Opened 12 months ago
cant change foreginkey from null=false to null=true in postgresql
| Reported by: | anonymous | Owned by: | andrew |
|---|---|---|---|
| Priority: | major | Milestone: | |
| Component: | commands | Version: | unknown |
| Keywords: | Cc: |
Description
I'm using South 0.7.5 and PostgreSQL 9.0.4 on x86_64-apple-darwin11.1.0, compiled by GCC i686-apple-darwin11-llvm-gcc-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00), 64-bit. I am starting with a new database, and migrations which may have been created by prior versions of South (0.7.3???). I get an error when trying to
The tail end of the stack trace is the following:
File "/Users/chema/envs/cf/lib/python2.7/site-packages/south/db/generic.py", line 533, in alter_column
field.rel.to._meta.get_field(field.rel.field_name).column
File "/Users/chema/envs/cf/lib/python2.7/site-packages/south/db/generic.py", line 273, in execute
cursor.execute(sql, params)
File "/Users/chema/envs/cf/lib/python2.7/site-packages/django/db/backends/util.py", line 34, in execute
return self.cursor.execute(sql, params)
File "/Users/chema/envs/cf/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 44, in execute
return self.cursor.execute(query, args)
django.db.utils.DatabaseError?: constraint "revoked_by_id_refs_id_4128367e0dc3da83" for relation "credits_transaction" already exists
I managed to fix this by changing south/db/generic.py to include the following:
# Drop all foreign key constraints
try:
self.delete_foreign_key(table_name, name)
except ValueError?:
# There weren't any
ignore_constraints=True #THIS IS THE LINE I ADDED
pass
