I have added a foreign key to a user to a model, but when I try to migrate the database using South, I get the following error:
_mysql_exceptions.OperationalError: (1067, "Invalid default value for 'user_id'")
South tells me that I may be able to recover from the error by running an SQL command:
! You *might* be able to recover with: =
ALTER TABLE `main_deal` DROP COLUMN `user_id` CASCADE; []
I tried to run the SQL command, but I get the following error:
#1091 - Can't DROP 'user_id'; check that column/key exists
Do I need to add 'user_id' to my model and set the default value to 1?
Edit: Here is the code that I added to my model to cause this to occur:
user = models.ForeignKey(User)
Then I migrated the model using South.
When you ran the schemamigration
command, you should've been asked some questions about default values. If you gave the wrong answer it may have caused the problem you describe.
If you could open up the actual migration file and grab the forward
method near the top, and post it here, I should be able to figure out what went wrong.