[英]Boolean Field Django Can't Migrate to Postgresql
Django Version 4.1 I have created migration in SQLite3 and want to change to Postgresql when i connect to Postgresql i've this error Django 版本 4.1 我在 SQLite3 中创建了迁移,并希望在我连接到 Postgresql 时更改为 Postgresql 我有这个错误
django.db.utils.ProgrammingError: cannot cast type smallint to boolean
LINE 1: ...R COLUMN "isProduct" TYPE boolean USING "isProduct"::boolean
this is my model这是我的 model
from django.db import models
class Item(models.Model):
name = models.CharField(max_length = 150)
slug = models.SlugField(unique = True, db_index=True, null=True)
pic = models.URLField(max_length = 400)
address = models.CharField(max_length = 150)
phone = models.CharField(max_length = 15)
price = models.IntegerField()
original_link = models.URLField(max_length = 400)
description = models.TextField(max_length = 1500)
additional_desc = models.TextField(max_length = 1500,default='')
material = models.TextField(max_length = 200, default = '')
weight = models.DecimalField(max_digits = 12, decimal_places = 2, default = 0)
weight_unit = models.CharField(max_length = 4, default = '')
color = models.CharField(max_length = 50, default = '')
dimension_length = models.DecimalField(max_digits = 12, decimal_places = 2, default = 0)
dimension_width = models.DecimalField(max_digits = 12, decimal_places = 2, default = 0)
dimension_height = models.DecimalField(max_digits = 12, decimal_places = 2, default = 0)
dimension_unit = models.CharField(max_length = 4, default='')
isProduct = models.BooleanField(default = True)
furniture_location = models.CharField(max_length = 100, default='')
def __str__(self):
return self.name
i've tried to change BooleanField
to SmallIntegerField
, PositiveSmallIntegerField
, and IntegerField
and the error still says the same thing我试图将
BooleanField
更改为SmallIntegerField
、 PositiveSmallIntegerField
和IntegerField
并且错误仍然说同样的话
How to fix this error because this error prevent sessions
and contenttype
table to be migrated如何修复此错误,因为此错误会阻止迁移
sessions
和contenttype
表
In my experience, if you tried to change something in Django models and the error stays the same it means you need to restart or delete the table and start migrating it.根据我的经验,如果您尝试更改 Django 模型中的某些内容并且错误保持不变,则意味着您需要重新启动或删除表并开始迁移它。 I suggest you do this Make sure the settings.py is connected to PostgreSQL
我建议你这样做确保 settings.py 连接到 PostgreSQL
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': '<PostgreSQL_DBName>',
'USER': '<PostgreSQL_UserName>',
'PASSWORD': '<PostgreSQL_Password>',
'HOST': '<PostgreSQL_HOST>',
'PORT': '<PostgreSQL_PORT>',
}
}
migrations/
migrations/
中的所有迁移python manage.py makemigrations
python manage.py migrate
**Notes If your PostgreSQL is localhost and you're accessing from pgAdmin **注意如果您的 PostgreSQL 是 localhost 并且您正在从 pgAdmin 访问
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.