Django 1 7 Makemigration non-nullable field

0 votes
I am trying to use django-orderedmodel in my project.

But, Running makemigrations doesn't work and it shows the following:

 You are trying to add a non-nullable field 'order' to slide without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
 1) Provide a one-off default now (will be set on all existing rows)
 2) Quit, and let me add a default in
Select an option:

Can anyone tell me what should I do to fix this?
May 9, 2019 in Python by ana1504.k
• 7,910 points

1 answer to this question.

0 votes
As the order field is unique, you'll need to add the field in several migration steps, replacing the original operations in your migration:

Add a nullable field, set the default to NULL.
Set the field to a unique value in each row.
Add a NOT NULL constraint.

You can use something like this:

operations = [
    migrations.AddField('myapp.MyModel', 'order', models.PositiveIntegerField(null=True, unique=True)),
    migrations.AlterField('myapp.MyModel', 'order', models.PositiveIntegerField(blank=True, unique=True)),
answered May 9, 2019 by SDeb
• 13,300 points

Related Questions In Python

0 votes
1 answer
0 votes
1 answer

Need help installing easy_install in Python 2.7.1 on Windows 7

That tool is part of the setuptools ...READ MORE

answered Dec 26, 2018 in Python by Nymeria
• 3,520 points
+1 vote
1 answer

How to install tensorflow using anaconda and python 3.7.1 on windows?

Since I am using python 3.5 so ...READ MORE

answered Aug 19, 2019 in Python by Arvind
• 3,000 points
0 votes
1 answer

how to download and install Django rest framework?

To install Django, you can simply open ...READ MORE

answered Apr 24, 2018 in Python by Christine
• 15,830 points
0 votes
1 answer
0 votes
1 answer

Host not allowed

Go to your project directory cd project cd project ALLOWED_HOSTS ...READ MORE

answered Aug 9, 2018 in AWS by Priyaj
• 58,140 points
0 votes
1 answer

How to install django 1.4?

This can be done by using this ...READ MORE

answered Jul 11, 2019 in Python by SDeb
• 13,300 points
0 votes
1 answer

How is Python 2.7.3 and Python 3.3 different?

raw_input() is not used in Python 3. Use input()  ...READ MORE

answered Sep 12, 2018 in Python by SDeb
• 13,300 points