The Python Oracle

django.db.utils.IntegrityError: column "color_set_id" contains null values

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Puzzle Game 3 Looping

--

Chapters
00:00 Question
02:01 Accepted answer (Score 2)
02:24 Answer 2 (Score 6)
02:55 Thank you

--

Full question
https://stackoverflow.com/questions/4627...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #django #python3x #djangomodels #djangoadmin

#avk47



ANSWER 1

Score 6


Follow these steps

  • python manage.py migrate --fake

  • comment color_set

  • python manage.py makemigrations && python manage.py migrate
  • uncomment color_set
  • python manage.py makemigrations && python manage.py migrate



ACCEPTED ANSWER

Score 2


The problem is because you added null=True after creating the migration file. Follow these steps now.

1) Drop ColorSet & Product tables from your local table database.
2) Delete all the migration files you created for these `CharField to a ForeignKey` change
3) execute `python manage.py makemigrations`
4) execute 'python manage.py migrate'