- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试通过syncdb
命令加载初始数据时,Django抛出以下错误:
django.db.utils.IntegrityError: Problem installing fixtures: The row in table 'user_profile_userprofile' with primary key '1' has an invalid foreign key: user_profile_userprofile.user_id contains a value '1' that does not have a corresponding value in user_customuser.id.
class UserProfile(TimeStampedModel):
user = models.OneToOneField(settings.AUTH_USER_MODEL, null=True, blank=True)
./manage.py dumpdata user --format=json --indent=4 --natural-foreign
会产生以下结果:
[
{
"fields": {
"first_name": "Test",
"last_name": "Test",
"is_active": true,
"is_superuser": true,
"is_staff": true,
"last_login": "2014-10-21T11:33:42Z",
"groups": [],
"user_permissions": [],
"password": "pbkdf2_sha256$12000$Wqd4ekGdmySy$Vzd/tIFIoSABP9J0GyDRwCgVh5+Zafn9lOiTGin9/+8=",
"email": "test@test.com",
"date_joined": "2014-10-21T11:22:58Z"
},
"model": "user.customuser",
"pk": 1
}
]
./manage.py dumpdata user_profile --format=json --indent=4 --natural-foreign
会产生以下结果:
[
{
"fields": {
"weight": 75.0,
"created": "2014-10-21T11:23:35.536Z",
"modified": "2014-10-21T11:23:35.560Z",
"height": 175,
"user": 1,
},
"model": "user_profile.userprofile",
"pk": 1
}
]
syncdb
试图在加载CustomUser之前加载UserProfile。
最佳答案
我猜您应该使用Migrations
https://docs.djangoproject.com/en/1.7/topics/migrations/,它们是有序的。但是,如果您使用的是Django 1.7之前的版本,请安装south
https://south.readthedocs.org/en/latest/
关于django - 使用SQLite使用OneToOneField加载Django固定装置时发生IntegrityError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26487579/
我在 app_name 文件夹的根目录下的 django 应用程序中运行脚本;就像在 app_name>app_name 中一样。 在脚本的顶部,我有这个: import os import sys
我正在使用 sqlite 数据库,我将模型声明为: class User(db.Model): __tablename__ = 'users' id = db.Column(db.In
我正在使用 sqlite 数据库并且我在这个要点中声明了模型 https://gist.github.com/mmahesh/7245561 我添加了一个带有事务管理器的模型实例作为 with tra
我的网页的注册 View (如下)通过 Django 的身份验证模型 User 创建了一个新用户,然后使用该新创建的用户 ID 通过我自己的模型 account.Users 添加更多信息。我的问题是,
我正在尝试使用复合主键创建一个表。它有一个整数和两个字符串字段作为键。当我提交 session 时,它会引发 IntegrityError .我在做什么有什么问题? class Targets(db.
当我尝试将新条目保存到名为“config”的表中时遇到了这个问题, class Config(models.Model): ident = models.CharField(max_lengt
找不到解决方案。我现在传递一个元组列表,其中包含要插入的信息而不是从其他表中提取的信息,问题就消失了。 我目前正在编写将要编辑表格的代码。我有几行信息要插入,但无论顺序如何,我总是在第四个元素上收到
我有 python 线程应用程序 + Postgres。我正在使用 Django 的 ORM保存到 Postgres.. 我有并发保存调用。偶尔有 2 个线程保存导致问题的相同主键。 Postgres
有人可以向我解释如何正确测试 Postgres 数据库错误,尤其是 IntegrityError。例如我有下一个测试: class TestSlugs(TestCase): # This sl
我在尝试删除 User 时收到 IntegrityError: IntegrityError: (1451, 'Cannot delete or update a parent row: a fo
在 python 中,我正在使用 importmany 填充 SQLITE 数据库,因此我可以一次导入数万行数据。我的数据包含在元组列表中。我在数据库中设置了我想要的主键。 我遇到的问题是主键错误会引
每当尝试附加文件时,我的应用程序(本地)都会引发ActiveStorage::IntegrityError错误。我如何摆脱这个错误? 我只有一个has_one_attached,但我不知道该错误是如何
我想插入几个User数据库中的行。我真的不在乎插入是否成功,只要我得到通知,在这两种情况下我都能做到,那么哪一个在性能(主要是速度)方面更好? 始终插入行(通过调用模型的 save 方法)并捕获潜在的
我开始使用 factory_boy 包,所以我设置了一些工厂并想测试创建的对象不会引发任何验证错误。 这是我正在使用的 mixin,它基本上从模块中获取每个工厂,创建一个实例,然后测试 .full_c
我有一个模型 LucyGuide,它通过 OneToOneField 扩展了 Django 的 User 模型: class LucyGuide(models.Model): user = m
我有一个模型 LucyGuide,它通过 OneToOneField 扩展了 Django 的 User 模型: class LucyGuide(models.Model): user = m
我正在尝试在 Django 中创建配方/成分模型 在我的 models.py 中我得到了 class Ingredient(models.Model): name = models.CharF
我正在使用 Django 构建一个简单的博客应用程序。我想实现使用表单添加新博客的功能。出现一些问题。 这是我的 models.py from django.db import models from
我知道还有许多其他问题与完全相同的问题有关,但我已经尝试过他们的答案,但到目前为止没有一个有效。 我正在尝试从与其他表有关系的表中删除记录。这些表中的外键是 nullable=false ,因此尝试删
我正在与普通/ guest 用户一起处理我的结帐 View ,但很难解决完整性错误。想法是让访客用户仅使用电子邮件注册才能结帐,我需要将用户电子邮件设置为唯一。 模型.py from django.c
我是一名优秀的程序员,十分优秀!