[Django]-Django.db.utils.IntegrityError: column "venue_city" contains null values

31πŸ‘

βœ…

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

πŸ‘€Anoop

7πŸ‘

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

πŸ‘€0n10n_

6πŸ‘

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.

πŸ‘€lapin

3πŸ‘

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πŸ‘

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
πŸ‘€DSAnup

0πŸ‘

As the error says, you have a null value in the "venue_city" column.

It seems at the time of defining your model you had not included "null=True".

So it returns null because there is nothing in your β€˜venue_city" variable. Consider deleting the last migration file and perform another migration using
python manage.py makemigrations and python manage.py migrate commands.

πŸ‘€Kibiku Brian

Leave a comment