django.db.utils.IntegrityError: column “venue_city” contains null values

前端 未结 5 1205
半阙折子戏
半阙折子戏 2021-01-04 10:08

I have read a lot of other posts here on stackoverflow and google but I could not find a solution.

It all started when I changed the model from a CharField to a For

相关标签:
5条回答
  • 2021-01-04 10:42

    I solved it by just adding null = True to both the (automatically generated) migration file that was causing the issue and in the Model. Then migrate again and your failed migration will now succeed. As you changed it also in your model, makemigration will detect no changes after that.

    0 讨论(0)
  • 2021-01-04 10:44

    I solved it by below:

    1. First delete last migration that face problem
    2. Then add like venue_city = models.CharField(blank=True, null=True)
    3. Finally use makemigrations and migrate command
    0 讨论(0)
  • 2021-01-04 10:56

    Had a similar problem i resolved it by removing the previous migration files.No technical explanation

    0 讨论(0)
  • 2021-01-04 10:58

    Looks like you added null=True after created migration file. Because venue_city is not a nullable field in your migration file

    Follow these steps.

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

    It should work

    0 讨论(0)
  • 2021-01-04 11:02

    follow the below steps:-

    • add null=True, blank=True in Venue model class eg: venue_city = models.ForeignKey(City, null=True, blank=True)
    • delete venues.0016_auto_20160514_2141 migration file from migrations folder in your app
    • then run python manage.py makemigrations
    • then run python manage.py migrate

    no need to drop table or remove migrations from migration tables

    0 讨论(0)
提交回复
热议问题