ValueError:字段gallery.likeGroup.likeGroupCustomerId:gallery.customers引用的模型的查找失败

时间:2015-05-01 07:28:56

标签: python django

我使用Django 1.8并收到以下错误:

ValueError: Lookup failed for model referenced by field gallery.likeGroup.likeGroupCustomerId: gallery.customers

models.py 如下所示:

from django.db import models

class artist(models.Model):
    artistName = models.CharField(primary_key = True, max_length = 20)
    artistBirthPlace = models.CharField(max_length = 20)
    artistAge = models.IntegerField(default = 0)
    artistStyle = models.CharField(max_length = 20, default = 'NULL')
    def __str__(self):
        return self.artistName

class customer(models.Model):
    customerId = models.IntegerField(primary_key = True)
    customerName = models.CharField(max_length = 20)
    customerAddress = models.CharField(max_length = 20)
    customerAmount = models.IntegerField(default = 0)
    def __str__(self):
        return self.customerName


class artwork(models.Model):
    artworkTitle = models.CharField(primary_key = True, max_length = 20)
    artworkYear = models.IntegerField(default = 0)
    artworkPrice = models.IntegerField(default = 0)
    artworkArtist = models.ForeignKey(artist, db_column = 'artistName')
    artworkType = models.CharField(default = 'NULL', max_length = 20)
    def __str__(self):
        return self.artworkTitle

class group(models.Model):
    groupName = models.CharField(primary_key = True, max_length = 20)
    def __str__(self):
        return self.groupName

#class likeGroup(models.Model):
#   likeGroupCustomerId = models.IntegerField(default = 0)
#   likeGroupName = models.ForeignKey(group, db_column = 'groupName')
#   def __str__(self):
#       return self.likeGroupName

class classifiedInto(models.Model):
    classifiedIntoGroupName = models.ForeignKey(group, db_column = 'groupName')
    classifiedIntoArtworkTitle = models.ForeignKey(artwork, db_column = 'artworkTitle')


class likeArtist(models.Model):
    likeArtistCustomerId = models.ForeignKey(customer, db_column = 'customerId')
    likeArtistArtistName = models.ForeignKey(artist, db_column = 'artistName')

admin.py 看起来像:

from django.contrib import admin

from .models import artist
class artistAdmin(admin.ModelAdmin):
    list_display = ('artistName', 'artistAge', 'artistBirthPlace','artistStyle')
    list_filter = ['artistName', 'artistAge', 'artistBirthPlace','artistStyle']
    search_fields = ['artistName', 'artistAge', 'artistBirthPlace','artistStyle'] 
admin.site.register(artist, artistAdmin)


from .models import customer
class customerAdmin(admin.ModelAdmin):
    list_display = ('customerId', 'customerName', 'customerAddress', 'customerAmount')
    list_filter = ['customerId', 'customerName', 'customerAddress', 'customerAmount']
    search_fields = ['customerId', 'customerName', 'customerAddress', 'customerAmount']
admin.site.register(customer, customerAdmin)


from .models import artwork
class artworkAdmin(admin.ModelAdmin):
    list_display = ('artworkTitle', 'artworkYear', 'artworkYear', 'artworkPrice', 'artworkArtist')
    list_filter = ['artworkTitle', 'artworkYear', 'artworkYear', 'artworkPrice', 'artworkArtist']
    search_fields = ['artworkTitle', 'artworkYear', 'artworkYear', 'artworkPrice', 'artworkArtist']
admin.site.register(artwork, artworkAdmin)


from .models import group
class groupAdmin(admin.ModelAdmin):
    list_filter = ['groupName']
    search_fields = ['groupName']
admin.site.register(group, groupAdmin)

#from .models import likeGroup
#class likeGroupAdmin(admin.ModelAdmin):
#   list_filter = [ 'likeGroupName']
#   search_fields = ['likeGroupName']
#admin.site.register(likeGroup, likeGroupAdmin)

from .models import likeArtist
class likeArtistAdmin(admin.ModelAdmin):
    list_display = ('likeArtistCustomerId', 'likeArtistArtistName')
    list_filter = ['likeArtistCustomerId', 'likeArtistArtistName']
    search_fields = ['likeArtistCustomerId', 'likeArtistArtistName']
admin.site.register(likeArtist, likeArtistAdmin)

from .models import classifiedInto
class classifiedIntoAdmin(admin.ModelAdmin):
    list_display = ('classifiedIntoGroupName', 'classifiedIntoArtworkTitle')
    list_filter = ['classifiedIntoGroupName', 'classifiedIntoArtworkTitle']
    search_fields = ['classifiedIntoGroupName', 'classifiedIntoArtworkTitle']
admin.site.register(classifiedInto, classifiedIntoAdmin)

当我尝试从Django应用程序中打开 LikeGroup 时,它会出错:

  

/ admin / gallery / likegroup /

中的OperationalError      

(1054,"未知列' gallery_likegroup.id'在'字段列表'")

0 个答案:

没有答案