Django: Why do some model fields clash with each other?

后端 未结 6 2306
南笙
南笙 2020-11-29 16:10

I want to create an object that contains 2 links to Users. For example:

class GameClaim(models.Model):
    target = models.ForeignKey(User)
    claimer = mod         


        
6条回答
  •  臣服心动
    2020-11-29 16:55

    I seem to come across this occasionally when I add a submodule as an application to a django project, for example given the following structure:

    myapp/
    myapp/module/
    myapp/module/models.py
    

    If I add the following to INSTALLED_APPS:

    'myapp',
    'myapp.module',
    

    Django seems to process the myapp.mymodule models.py file twice and throws the above error. This can be resolved by not including the main module in the INSTALLED_APPS list:

    'myapp.module',
    

    Including the myapp instead of myapp.module causes all the database tables to be created with incorrect names, so this seems to be the correct way to do it.

    I came across this post while looking for a solution to this problem so figured I'd put this here :)

提交回复
热议问题