0

when I run python manage.py migrate I keep getting the following error.

django.db.utils.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'None) NOT NULL, user_id_id integer NOT NULL)' at line 1")

I'm running Python 3.8.6, and mysqlclient 2.0.1 and Django 3.1.3.

Model

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"

View

# 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()

Admin

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)

Serializer


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')

I'm not sure if I'm missing something?

S.Selvar
  • 1
  • 3

1 Answers1

0

Seems to have a typing mistake. In serializer, you have typed user_id. There is no such field in your GrantProfile model. It should be user. And also you have imported GrantProfile model twice in serializers.

Saijal Shakya
  • 122
  • 3
  • 9
  • So I changed the user -> user_id but that wasn't the issue. The error is saying that the I'm running the wrong syntax for the query. – S.Selvar Nov 30 '20 at 05:44