Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
79 views
in Technique[技术] by (71.8m points)

python - Unkown Column error on django admin, how to fix it?

i have an error in my django admin:

(1054, "Unknown column 'flora2estado.id' in 'field list'")

the model flora2estado has two fields, they are used in unique together as a pseudo composite key, how can i fix this?

admin.py admin.site.register(Flora2Estado)

models.py

    estado = models.OneToOneField(Estados, models.DO_NOTHING, primary_key=True)
    especie_id = models.IntegerField()
    flora2estado = models.IntegerField(blank=True, null=True)
    class Meta:
        managed = False
        db_table = 'flora2estado'
        unique_together = (('estado', 'especie_id'),)

I tried to add the "flora2estado" field without sucess.

All migrations done, thank you for your time

question from:https://stackoverflow.com/questions/65833607/unkown-column-error-on-django-admin-how-to-fix-it

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Django is trying to select id field, as documented

By default, Django gives each model the following field:

id = models.AutoField(primary_key=True)

If you’d like to specify a custom primary key, specify primary_key=True on one of your fields. If Django sees you’ve explicitly set Field.primary_key, it won’t add the automatic id column.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...