Question

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.

Was it helpful?

Solution

Drop the unique index.

OTHER TIPS

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

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top