【发布时间】:2021-03-12 01:44:07
【问题描述】:
当我运行 python manage.py migrate 时,我不断收到以下错误。
django.db.utils.ProgrammingError: (1064, "您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,以了解在 'None 附近使用的正确语法) NOT NULL, user_id_idinteger NOT NULL)' 在第 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')
我不确定我是否遗漏了什么?
【问题讨论】:
标签: python mysql django django-rest-framework django-3.1