我有这个自定义User
模型,其中我已将 primary_key 更改为email
字段,如下所示:
class User(AbstractBaseUser, PermissionsMixin):
# Primary Key of my model
email = models.EmailField(max_length=254, primary_key=True)
username = models.CharField(_('username'),max_length=30,
unique=True,
help_text=_('Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only.'),
validators=[
RegexValidator(
r'^[\w.ñ@+-]+$',
_('Enter a valid username. This value may contain only '
'letters, numbers ' 'and @/./+/-/_ characters.')
),
],
error_messages={
'unique': _("A user with that username already exists."),
},
)
first_name = models.CharField(max_length=50,blank=True, null=True,
)
last_name=models.CharField(max_length=50, blank=True, null=True,)
is_staff = models.BooleanField(
default=True,
help_text='Designates whether the user can log into this admin site.')
is_active = models.BooleanField(default=True)
date_joined = models.DateTimeField(default=timezone.now)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']
objects = UserManager()
我还有另一个名为Match
:
class Match(models.Model):
match_date = models.DateTimeField(default=timezone.now, null=True)
home_team_players_accept = models.ManyToManyField(
settings.AUTH_USER_MODEL,
related_name='home_team_players_accept',
blank=True,)
away_team_players_accept = models.ManyToManyField(
settings.AUTH_USER_MODEL,
related_name='away_team_players_accept',
blank=True,)
home_team_players_cancel = models.ManyToManyField(
settings.AUTH_USER_MODEL,
related_name='home_team_players_cancel',
blank=True,)
away_team_players_cancel = models.ManyToManyField(
settings.AUTH_USER_MODEL,
related_name='away_team_players_cancel',
blank=True,)
fichaje_players_match = models.ManyToManyField(
settings.AUTH_USER_MODEL,
related_name='fichaje_players_match',
blank=True,)
当我执行时,python manage.py migrate
我得到这个输出:
File "/home/bgarcial/.virtualenvs/fuupbol2/lib/python3.5/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.InternalError: cannot drop constraint auth_user_pkey on table auth_user because other objects depend on it
DETAIL: constraint auth_user_groups_user_id_6a12ed8b_fk_auth_user_username on table auth_user_groups depends on index auth_user_pkey
constraint auth_user_user_permissio_user_id_a95ead1b_fk_auth_user_username on table auth_user_user_permissions depends on index auth_user_pkey
constraint games_information_match__user_id_246b2ea3_fk_auth_user_username on table games_information_match_away_team_players_cancel depends on index auth_user_pkey
constraint games_information_match__user_id_9d9f8df1_fk_auth_user_username on table games_information_match_home_team_players_cancel depends on index auth_user_pkey
constraint games_information_match__user_id_79122347_fk_auth_user_username on table games_information_match_fichaje_players_match depends on index auth_user_pkey
constraint games_information_match__user_id_54e7681b_fk_auth_user_username on table games_information_match_away_team_players_accept depends on index auth_user_pkey
constraint games_information_match__user_id_14203632_fk_auth_user_username on table games_information_match_home_team_players_accept depends on index auth_user_pkey
HINT: Use DROP ... CASCADE to drop the dependent objects too.
我找到了一些关于这个场景案例的参考资料,但我不明白如何解决这个不便
我什至尝试删除整个数据库,但不便仍然存在。