Ton*_*dis 1 python django postgresql django-models django-1.10
我尝试运行makemigrations并在迁移后我不断收到此错误:
ValueError: Related model 'users.UserProfile' cannot be resolved
Run Code Online (Sandbox Code Playgroud)
我想要做的是将UserProfile模型链接到Django自己的用户模型:
from django.db import models
from django.contrib.auth.models import User
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
website = models.URLField(blank=True)
bio = models.CharField(max_length=250, blank=True)
full_name = models.CharField(max_length=250, blank=True)
Run Code Online (Sandbox Code Playgroud)
" 竞赛 "模型(如下面我已安装的应用程序中所示)也使用用户模型,没有任何错误.
我安装的应用程序如下所示:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'users',
'social.apps.django_app.default',
'crispy_forms',
'pages',
'contests',
]
Run Code Online (Sandbox Code Playgroud)
我的迁移文件0001_initial.py如下:
# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2016-12-30 15:45
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='UserProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('website', models.URLField(blank=True)),
('bio', models.CharField(blank=True, max_length=250)),
('full_name', models.CharField(blank=True, max_length=250)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Run Code Online (Sandbox Code Playgroud)
其他说明:
我使用多个设置文件,但我安装的应用程序都在我的基本设置文件中,所以这不应该是问题.
我正在使用Python Social Auth创建管道并创建UserProfile.(但这不会对数据库中模型的创建产生任何影响)
我甚至删除了数据库并重新创建它但我仍然得到同样的错误.
提前致谢!!!:)
尝试为每个模型一一运行迁移。
这样您就可以调试app您面临的问题
python manage.py migrate appmname
Run Code Online (Sandbox Code Playgroud)
也许一项一项地运行迁移可能会有所帮助
| 归档时间: |
|
| 查看次数: |
2153 次 |
| 最近记录: |