psycopg2.ProgrammingError: column "..." does not exist - through makemigrations error?
psycopg2.ProgrammingError: column "..." does not exist - through makemigrations error?
我将一个项目推送到 heroku 上,但似乎无法通过其上的 makemigrations 取胜。
所以起初我认为一切顺利。推送之后,我进行了迁移并创建了超级用户。除了一个部分: accounts_userprofileinfo 之外,一切看起来都很好,管理员工作正常。一旦我尝试在管理员中单击 table,就会出现此错误:
Internal Server Error: /admin/accounts/userprofileinfo/
Traceback (most recent call last):
File
"/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py",
line 65, in execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: column accounts_userprofileinfo.daca does
not exist
LINE 1: SELECT "accounts_userprofileinfo"."id",
"accounts_userprofil...
通常您不会在实时服务器上执行 makemigrations,但我认为它可能会修复它,所以我做了。令人惊讶的是它有一个结果:
Migrations for 'auth':
.heroku/python/lib/python3.6/site-packages/django/contrib/auth/migrations/0009_auto_20180709_2242.py
- Alter field email on user
本地我的 makemigrations 有结果:没有变化,但无论如何一切正常。有趣的是,对于 heroku postgres,无论我多久进行一次 makemigrations,相同的事情都会随着 auth 的迁移不断弹出,就像它没有保存它一样。不确定这是否会导致我的 account_userprofileinfo 服务器出错,但有可能。
账户模型:
User._meta.get_field('email').__dict__['_unique'] = True
class UserProfileInfo(models.Model):
TYPE_CHOICES = (
('yes', 'yes'),
('no', 'no'),
)
POSITION_CHOICES = (
('President', 'President'),
('Vize-President', 'Vize-President'),
('Secretary', 'Secretary'),
('Member', 'Member'),
)
daca = models.CharField(max_length=100, choices=TYPE_CHOICES, default="no")
committee = models.CharField(max_length=30, choices=POSITION_CHOICES, default="Member")
user = models.OneToOneField(User)
city = models.CharField(max_length=75, blank=False, default='')
mobile = models.CharField(max_length=16,blank=False, default='')
experience = models.IntegerField(blank=False, default='0')
profile_picture = ThumbnailerImageField(upload_to='profile_pics',blank=True, default='/placeholder/neutral3.png',
resize_source=dict(size=(550, 700)))
joined_date = models.DateTimeField(default=timezone.now, blank=True, null=True,editable=False)
def __str__(self):
# Built-in attribute of django.contrib.auth.models.User !
return self.user.first_name + " " + self.user.last_name
def create_profile(sender, **kwargs):
user = kwargs["instance"]
if kwargs["created"]:
user_profile = UserProfileInfo(user=user)
user_profile.save()
post_save.connect(create_profile, sender=User)
有什么想法吗?谢谢
运行 也 manage.py 迁移。此外,我不确定您是否真的需要 User._meta.get_field('email').__dict__['_unique'] = True
。猴子修补默认模型导致在 Django 本身内部创建新的迁移,我会说这是不好的。要更改默认字段,您最好创建自定义用户模型 https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#substituting-a-custom-user-model。但是在已经创建的项目中很难制作。所以也许处理表单中的唯一检查。
我将一个项目推送到 heroku 上,但似乎无法通过其上的 makemigrations 取胜。
所以起初我认为一切顺利。推送之后,我进行了迁移并创建了超级用户。除了一个部分: accounts_userprofileinfo 之外,一切看起来都很好,管理员工作正常。一旦我尝试在管理员中单击 table,就会出现此错误:
Internal Server Error: /admin/accounts/userprofileinfo/
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 65, in execute return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: column accounts_userprofileinfo.daca does not exist
LINE 1: SELECT "accounts_userprofileinfo"."id", "accounts_userprofil...
通常您不会在实时服务器上执行 makemigrations,但我认为它可能会修复它,所以我做了。令人惊讶的是它有一个结果:
Migrations for 'auth':
.heroku/python/lib/python3.6/site-packages/django/contrib/auth/migrations/0009_auto_20180709_2242.py
- Alter field email on user
本地我的 makemigrations 有结果:没有变化,但无论如何一切正常。有趣的是,对于 heroku postgres,无论我多久进行一次 makemigrations,相同的事情都会随着 auth 的迁移不断弹出,就像它没有保存它一样。不确定这是否会导致我的 account_userprofileinfo 服务器出错,但有可能。
账户模型:
User._meta.get_field('email').__dict__['_unique'] = True
class UserProfileInfo(models.Model):
TYPE_CHOICES = (
('yes', 'yes'),
('no', 'no'),
)
POSITION_CHOICES = (
('President', 'President'),
('Vize-President', 'Vize-President'),
('Secretary', 'Secretary'),
('Member', 'Member'),
)
daca = models.CharField(max_length=100, choices=TYPE_CHOICES, default="no")
committee = models.CharField(max_length=30, choices=POSITION_CHOICES, default="Member")
user = models.OneToOneField(User)
city = models.CharField(max_length=75, blank=False, default='')
mobile = models.CharField(max_length=16,blank=False, default='')
experience = models.IntegerField(blank=False, default='0')
profile_picture = ThumbnailerImageField(upload_to='profile_pics',blank=True, default='/placeholder/neutral3.png',
resize_source=dict(size=(550, 700)))
joined_date = models.DateTimeField(default=timezone.now, blank=True, null=True,editable=False)
def __str__(self):
# Built-in attribute of django.contrib.auth.models.User !
return self.user.first_name + " " + self.user.last_name
def create_profile(sender, **kwargs):
user = kwargs["instance"]
if kwargs["created"]:
user_profile = UserProfileInfo(user=user)
user_profile.save()
post_save.connect(create_profile, sender=User)
有什么想法吗?谢谢
运行 也 manage.py 迁移。此外,我不确定您是否真的需要 User._meta.get_field('email').__dict__['_unique'] = True
。猴子修补默认模型导致在 Django 本身内部创建新的迁移,我会说这是不好的。要更改默认字段,您最好创建自定义用户模型 https://docs.djangoproject.com/en/2.0/topics/auth/customizing/#substituting-a-custom-user-model。但是在已经创建的项目中很难制作。所以也许处理表单中的唯一检查。