I have a model with a CharField that earlier had "unique" set to True, but wich now is changed to False. But when i try to save that 开发者_运维问答field with something that exists django still throws an IntegrityError.
How can i change this behavior so that it allows non distinct values?
The database is MySQL.
I suggest using http://south.aeracode.org, it's a DB migration app for Django and it allows to make such changes without even touching MySQL shell/admin. This way you have kind of replayable macros for updating any computer to the latest DB scheme.
And using it is as simple as what they have written here: http://south.aeracode.org/wiki/ConvertingAnApp
Drop the unique index.
have you made sure that you re-synced your database in django using the "python manage.py syncdb" command at the command line before re-running your web application? This might solve your problem.
I was attempting to do the same thing, and found that as of django-south 0.5, south doesn't handle this for you.
Like was stated in the previous comments, you should probably create your south migration first, but then you will have to manually go in and delete the unique index that django initially creates when you do your first syncdb.
use mydb;
desc mytable;
That will show you the schema for the table, and you will see that the field will still have a value of "UNI" in the key column.
SHOW INDEX FROM mytable FROM mydb;
Should be an index that has Non_unique set to 0.
ALTER TABLE mytable DROP INDEX indexname;
If you look at the table schema again, you will see that "UNI" is no longer in the key column.
精彩评论