MySQL gives an “Unknown column 'user.id' in 'field list'” error using Django's automatic id

前端 未结 2 2025
一整个雨季
一整个雨季 2021-01-26 11:23

I have my User model set up with no primary key so that the automatic id will be used instead. However, when I try to access it using Django\'s \"

2条回答
  •  感动是毒
    2021-01-26 12:04

    EDIT : wrong answer. check comments below

    The problem is that you have managed set to False. According to the documentation

    If False, no database table creation or deletion operations will be performed for this model. This is useful if the model represents an existing table or a database view that has been created by some other means. This is the only difference when managed=False. All other aspects of model handling are exactly the same as normal. This includes

    Adding an automatic primary key field to the model if you don’t declare it. To avoid confusion for later code readers, it’s recommended to specify all the columns from the database table you are modeling when using unmanaged models.

    You will need to define the primary key as this is not done by default anymore.

提交回复
热议问题