我以前在我的笔记本电脑上运行我的网站,它的数据库是Sqlite,最近我想把它转移到DigitalOcean,我把它的数据库改成了Postgresql,但是我在迁移时遇到了一些问题.
I use to run my website on my laptop and its database was Sqlite, recently I wanted to transfer it to DigitalOcean and I changed its database to Postgresql, but when I migrate I encounters with some problems.
Python 3.4Django 1.8
Python 3.4 Django 1.8
django.db.utils.ProgrammingError: multiple default values specified for column "id" of table "profiles_userprofile"我的模特
class UserProfile(models.Model): user = models.OneToOneField(User) avatar = models.ImageField(blank=True, upload_to=get_image_path, default='/static/image/avatar/male.png') age = models.IntegerField(default=4, validators=[MinValueValidator(3), MaxValueValidator(99)])我该怎么办?
推荐答案尝试明确指定 id 字段并将其标记为主键:
Try explicitly specifying the id field and marking it as the primary key:
class UserProfile(models.Model): id = models.BigIntegerField(primary_key = True) user = models.OneToOneField(User) avatar = models.ImageField(blank=True, upload_to=get_image_path, default='/static/image/avatar/male.png') age = models.IntegerField(default=4, validators=[MinValueValidator(3), MaxValueValidator(99)])Django 应该自动为这个字段创建一个序列.
Django should automatically create a sequence for this field.
可能是 User 没有明确定义主键的外键混淆了 ORM,尽管这只是一个理论.
It may be that the User foreign key without an explicitly defined primary key is confusing the ORM, although that's just a theory.
更多推荐
为列“id"指定的多个默认值桌子的
发布评论