0

当我运行 python manage.py migrate 时,我不断收到以下错误。

user_id_id在_第 1 行")

我正在运行 Python 3.8.6、mysqlclient 2.0.1 和 Django 3.1.3。

模型

from ..assets.provinces import PROVINCE_CHOICES
from ..assets.industries import INDUSTRY_CHOICES
from django.contrib.auth.models import User


class GrantProfile(models.Model):
    user_id = models.ForeignKey(User,
                             models.SET_NULL,
                             blank=True,
                             null=True)
    province = models.CharField(
        max_length=2,
        choices=PROVINCE_CHOICES,
        help_text="Province your organization is based out of"
    )
    company_size = models.IntegerField(help_text="Company size")

    industry = models.CharField(
        max_length=150,
        choices=INDUSTRY_CHOICES,
        help_text="Industry your organization is part of."
    )

    class Meta:
        db_table = "grantprofiles"

看法

# Grant Profile View
from rest_framework import viewsets
from ..serializers.grantprofile import GrantProfileSerializer
from ..models.grantprofile import GrantProfile


class GrantProfileView(viewsets.ModelViewSet):
    serializer_class = GrantProfileSerializer
    queryset = GrantProfile.objects.all()

行政

from django.contrib import admin
from ..models.grantprofile import GrantProfile


# Grant Profile Admin

class GrantProfileAdmin(admin.ModelAdmin):
    list_display = ('user_id', 'province', 'company_size', 'industry')


admin.site.register(GrantProfile, GrantProfileAdmin)

串行器


from rest_framework import serializers
from ..models.grantprofile import GrantProfile


class GrantProfileSerializer(serializers.ModelSerializer):
    class Meta:
        model = GrantProfile
        fields = ('user_id', 'province', 'company_size', 'industry')

我不确定我是否遗漏了什么?

4

1 回答 1

0

好像有打字错误。在序列化程序中,您输入了user_idGrantProfile模型中没有这样的字段。它应该是用户。而且您在序列化程序中两次导入了 GrantProfile 模型。

于 2020-11-30T05:31:27.757 回答