简体   繁体   English

django // 1054,“字段列表”中的未知列“rank.post_id_id””

[英]django// 1054, Unknown column 'rank.post_id_id' in 'field list'"

django=2.2.3 mariadb django=2.2.3 mariadb

This error occurs after importing model from an existing database with 'inspectdb' and changed field properties.从具有“inspectdb”的现有数据库中导入 model 并更改字段属性后,会发生此错误。

class Post(models.Model):
    post_id = models.AutoField(primary_key=True)
    post_name = models.CharField(max_length=255, blank=True, null=True)
    email = models.CharField(max_length=255, blank=True, null=True)

class Rank(models.Model):
    rank_id = models.AutoField(primary_key=True)
    rank_type = models.IntegerField(blank=True, null=True)
    created_at = models.DateTimeField()
    # post_id = models.IntegerField(blank=True, null=True)
    post_id = models.ForeignKey(Post, on_delete=models.SET_NULL, blank=True, null=True)

Originally, it was # post_id, but I removed "managed = False", changed it to ForeignKey and then "migrate".原来是#post_id,但是我去掉了“managed = False”,改成了ForeignKey,然后“迁移”了。 As far as I know that if the "post_id" in the "Post" model is "primary_key True", it replaces the "id" value with "post_id".据我所知,如果“Post”model 中的“post_id”是“primary_key True”,它会将“id”值替换为“post_id”。 But "Django" keeps calling up the "post_id_id".但是“Django”不断调用“post_id_id”。 There is no command to refer to post_id_id elsewhere.没有命令可以在别处引用 post_id_id。 If you have a solution or something that I'm missing, please give me some advice.如果您有解决方案或我缺少的东西,请给我一些建议。

-------Add more after commented by Daniel Roseman -------- --------在丹尼尔罗斯曼评论后添加更多内容--------

class Post(models.Model):
    post_id = models.AutoField(primary_key=True)
    post_name = models.CharField(max_length=255, blank=True, null=True)
    email = models.CharField(max_length=255, blank=True, null=True)

class Gallery(models.Model):
    uid = models.AutoField(prymary_key=True)
    gallery_name = models.CharField(...)


class Rank(models.Model):
    rank_id = models.AutoField(primary_key=True)
    rank_type = models.IntegerField(blank=True, null=True)
    created_at = models.DateTimeField()
    # post_id = models.IntegerField(blank=True, null=True)
    post_id = models.ForeignKey(Post, on_delete=models.SET_NULL, blank=True, null=True)
    # uid = models.IntegerField(blank=True, null=True)
    uid = models.ForeignKey(Gallery, on_delete=models.SET_NULL, blank=True, null=True)

Don't call your ForeignKey post_id .不要打电话给你的 ForeignKey post_id Call it post .称它为post The underlying database field is post_id ;底层数据库字段是post_id Django adds the _id suffix automatically. Django 自动添加_id后缀。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 1054,django 中的“字段列表”中的“未知列 'work_waterlevel.id'” - 1054, "Unknown column 'work_waterlevel.id' in 'field list'" in django Django 模型(1054,“'字段列表'中的未知列”) - Django Models (1054, “Unknown column in 'field list'”) Django 1054 - 字段列表中的未知列 - Django 1054 - Unknown Column in field list 1054““字段列表”中的未知列“ user_account_id_fk_id”” - 1054, “Unknown column 'user_account_id_fk_id' in 'field list'” OperationalError:(1054,““字段列表”中的未知列“ snippets_snippet.owner_id””) - OperationalError : (1054, “Unknown column 'snippets_snippet.owner_id' in 'field list'”) sqlalchemy.exc.OperationalError:(MySQLdb._exceptions.OperationalError)(1054,“'字段列表'中的未知列'detail.id'”) - sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1054, "Unknown column 'detail.id' in 'field list'") (1054,“'字段列表'中的未知列'nan'”)Django bulk_create - (1054, “Unknown column 'nan' in 'field list'”) Django bulk_create OperationalError(1054,““字段列表”中的未知列“月””) - OperationalError (1054, “Unknown column 'month' in 'field list'”) (1054,“字段列表”中的未知列“日期””) - (1054, “Unknown column 'date' in 'field list'”) MySQL使用Django的自动ID给出“字段列表中的未知列'user.id'”错误 - MySQL gives an “Unknown column 'user.id' in 'field list'” error using Django's automatic id
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM