I know that from Django 1.7 I don\'t need to use South or any other migration system, so I am just using simple command python manage.py makemigrations
In case anyone is setting a ForeignKey
, you can just allow nullable fields without setting a default:
new_field = models.ForeignKey(model, null=True)
If you already have data stored within the database, you can also set a default value:
new_field = models.ForeignKey(model, default=<existing model id here>)
If the SSH it gives you 2 options, choose number 1, and put "None". Just that...for the moment.
In models.py
class UserProfile(models.Model):
user = models.OneToOneField(User)
website = models.URLField(blank=True)
new_field = models.CharField(max_length=140, default="some_value")
You need to add some values as default.
You need to provide a default value:
new_field = models.CharField(max_length=140, default='SOME STRING')
I was early in my development cycle, so this may not work for everyone (but I don't see why it wouldn't).
I added blank=True, null=True
to the columns where I was getting the error. Then I ran the python manage.py makemigrations
command.
Immediately after running this command (and before running python manage.py migrate
), I removed the blank=True, null=True
from all the columns. Then I ran python manage.py makemigrations
again. I was given an option to just change the columns myself, which I selected.
Then I ran python manage.py migrate
and everything worked well!
In new_file add the boolean property null.
new_field = models.CharField(max_length=140, null=True)
after you run a ./manage.py syncdb
for refresh the DB.
and finally you run ./manage.py makemigrations
and ./manage.py migrate