为列“id"指定的多个默认值桌子的

编程入门 行业动态 更新时间:2024-10-08 22:45:59
本文介绍了为列“id"指定的多个默认值桌子的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我以前在我的笔记本电脑上运行我的网站,它的数据库是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"指定的多个默认值桌子的

本文发布于:2023-10-16 13:56:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497765.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   默认值   桌子   id   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!