Have a Django / MySQL set up. There’s a model, Survey, which currently looks like…
class Survey(models.Model):
company = models.ForeignKey('Company')
I want to set up the model, so company can be a null value:
company = models.ForeignKey('Company', blank = True, null = True)
However, I’m not sure what I should do on the MySQL side to ensure all the existing constraints / models. Do I just alter the column through the console to accept null values? It’s a live database, so I don’t want to experiment too much (my development environment uses SqlLite3).
Update your model so that
blank=True, null=True. Then run thesqlallcommand on your production server (so that it gives the output for MySQL)Find the create table statement This will show the new definition for the
survey_idfield.Then, in your database shell, modify the column to accept null values using the
ALTER TABLEcommand.Be careful, and consider whether you want to run MySQL in your development environment as well. Do you really want to be copying and pasting commands from Stack Overflow into your live DB shell without testing them first?