简体   繁体   English

/django.db.utils.IntegrityError:NOT NULL约束失败/在python manage.py之后迁移应用程序零

[英]/django.db.utils.IntegrityError: NOT NULL constraint failed/ after python manage.py migrate app zero

I had some mess with migrations in production and localy. 我在生产和本地迁移时遇到了一些麻烦。 Finally the situation was that in production there were only initial migration and localy there were 8 migrations or something. 最后情况是,在生产中只有初始迁移,而且当地有8次迁移或其他东西。 So I decided to use 所以我决定使用

python manage.py migrate app zero 

both in production and localy(django 1.8.7). 在生产和localy(django 1.8.7)。 In prodcution it worked but locally it raised error which didn't appear before after makemigrations or migrate command. 在生产中它起作用但在本地它引发了错误,这在makemigrationsmigrate命令之后没有出现。

django.db.utils.IntegrityError: NOT NULL constraint failed: app_userprofile__new.phone_number

after few attempts to try different things, the error began to appear after migrate commands too. 在几次尝试尝试不同的事情之后,错误也开始出现在迁移命令之后。

The model itself : 模型本身:

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    phone_number = models.IntegerField(null=True, blank=True, default=None)

Check your local database. 检查您的本地数据库。

This error usually happens when one or more records do not meet the NOT NULL requirement 当一个或多个记录不符合NOT NULL要求时,通常会发生此错误

    UserProfile.objects.filter(phone_number=None)

You can resolve this by filling the phone_number field of the objects found 您可以通过填写找到的对象的phone_number字段来解决此问题

Or deleting objects that do not have filled phone_number 或者删除没有填充phone_number的对象

UPDATE UPDATE

Manage database changes with database migrations can prevent this type of situation 使用database migrations管理数据库更改可以防止此类情况

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django makemigrations工作,迁移失败“django.db.utils.IntegrityError:NOT NULL约束失败” - Django makemigrations works, migrate fails with “django.db.utils.IntegrityError: NOT NULL constraint failed” Createsuperuser django.db.utils.IntegrityError: NOT NULL 约束失败 - Createsuperuser django.db.utils.IntegrityError: NOT NULL constraint failed django.db.utils.IntegrityError:NOT NULL约束失败 - django.db.utils.IntegrityError: NOT NULL constraint failed django.db.utils.IntegrityError: NOT NULL 约束失败: - django.db.utils.IntegrityError: NOT NULL constraint failed: django.db.utils.IntegrityError: NOT NULL 约束失败来自 Postman - django.db.utils.IntegrityError: NOT NULL constraint failed fom Postman django.db.utils.IntegrityError: NOT NULL 约束失败:app_users.key_value_id - django.db.utils.IntegrityError: NOT NULL constraint failed: app_users.key_value_id django.db.utils.IntegrityError:NOT NULL 约束失败:app.area_id - django.db.utils.IntegrityError: NOT NULL constraint failed: app.area_id django.db.utils.IntegrityError: NOT NULL 约束失败:app_user.zip - django.db.utils.IntegrityError: NOT NULL constraint failed: app_user.zip django.db.utils.IntegrityError: NOT NULL 约束失败:new__inventory_app_item.accounting_class_id - django.db.utils.IntegrityError: NOT NULL constraint failed: new__inventory_app_item.accounting_class_id Django tests.py django.db.utils.IntegrityError:唯一约束失败:auth_user.username - Django tests.py django.db.utils.IntegrityError: UNIQUE constraint failed: auth_user.username
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM