DjangoでAbstractUerを使ったときのエラーをメモ
見慣れないエラーを出したのでメモしておく。
django.contrib.auth.models.AbstractUserを継承したモデルを作成
設定ファイルのミスなどでAUTH_USER_MODELを指定していない場合以下のエラーがでる。
ないとGroupやUserPermissionとUserの関連テーブルが重複するのでエラーになるらしい。
django 1.6
CommandError: One or more models did not validate: auth.user: Accessor for m2m field 'groups' clashes with related m2m field 'Group.user_set'. Add a related_name argument to the definition for 'groups'. auth.user: Accessor for m2m field 'user_permissions' clashes with related m2m field 'Permission.user_set'. Add a related_name argument to the definition for 'user_permissions'. accounts.account: Accessor for m2m field 'groups' clashes with related m2m field 'Group.user_set'. Add a related_name argument to the definition for 'groups'. accounts.account: Accessor for m2m field 'user_permissions' clashes with related m2m field 'Permission.user_set'. Add a related_name argument to the definition for 'user_permissions'.
django 1.7aではちょっとメッセージが変更されて、さらにHINTが表示されるようになっている。
CommandError: System check identified some issues: ERRORS: accounts.Account.groups: (E016) Clash between accessors for Account.groups and User.groups. HINT: Add or change a related_name argument to the definition for Account.groups or User.groups. accounts.Account.user_permissions: (E016) Clash between accessors for Account.user_permissions and User.user_permissions. HINT: Add or change a related_name argument to the definition for Account.user_permissions or User.user_permissions. auth.User.groups: (E016) Clash between accessors for User.groups and Account.groups. HINT: Add or change a related_name argument to the definition for User.groups or Account.groups. auth.User.user_permissions: (E016) Clash between accessors for User.user_permissions and Account.user_permissions. HINT: Add or change a related_name argument to the definition for User.user_permissions or Account.user_permissions.