Python – Django: Model name clash


I am trying to use different open source apps in my project. Problem is that there is a same Model name used by two different apps with their own model definition.

I tried using:

    class Meta:
        db_table = "db_name"

but it didn't work. I am still getting field name clash error at syncdb. Any suggestions.


I am actually trying to integrate Satchmo with Pinax. And the error is:

Error: One or more models did not validate: Accessor for field 'user' clashes with related m2m field 'User.contact_set'. Add a related_name argument to the definition for 'user'. Accessor for m2m field 'users' clashes with related field User.contact_set'. Add a related_name argument to the definition for 'users'.

You are right, table names are already unique. I analyzed the model and the Model 'Contact' is in two models of two different apps. When I comment out one of these models, it works fine.

May be the error is there because both apps are in PYTHON_PATH and when other app defines the its model with same name the clash occurs.

Best Solution

The problem is that both Satchmo and Pinax have a Contact model with a ForeignKey to User. Django tries to add a "contact_set" reverse relationship attribute to User for each of those ForeignKeys, so there is a clash.

The solution is to add something like related_name="pinax_contact_set" as an argument to the ForeignKey in Pinax's Contact model, or similarly in the Satchmo Contact model. That will require editing the source directly for one or the other. You might be able to find a way to do it via monkeypatching, but I'd expect that to be tricky.