django - 从 sqlite 迁移到 postgree 后,Django value too long for type character varying(20) 错误
问题描述
我有一个有点奇怪的问题:从 sqlite 迁移到 postgree 后,我不断从 db 后端收到此错误:
类型字符变化的值太长(20)
该字段的代码如下:
boat_name = models.CharField(max_length=50, unique=True, db_index=True, verbose_name="Boat model", help_text="Please input boat model")
所有迁移都已完成并运行
PGADMIN 中的 max_length 已更改为 50 - 无效。
命令:
ALTER TABLE boats_boatmodel ALTER COLUMN boat_name TYPE VARCHAR(50)
已运行 - 没有效果。
它可能是什么?
在这种情况下,使用 CharField 小部件更改为 TextField 会有所帮助吗???
谢谢!
移民:
class Migration(migrations.Migration):
initial = True
dependencies = [
('auth', '0009_alter_user_last_name_max_length'),
]
operations = [
migrations.CreateModel(
name='ExtraUser',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
('email', models.EmailField(blank=True, max_length=254, verbose_name='email address')),
('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
('is_activated', models.BooleanField(db_index=True, default=True, verbose_name='Is user activated?')),
('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
],
options={
'verbose_name': 'user',
'verbose_name_plural': 'users',
'abstract': False,
},
managers=[
('objects', django.contrib.auth.models.UserManager()),
],
),
migrations.CreateModel(
name='BoatImage',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('boat_photo', models.ImageField(blank=True, help_text='Please attach any photo of the boat', upload_to='photos/', verbose_name='Boat photo')),
],
options={
'verbose_name': 'Boat photo',
'verbose_name_plural': 'Boat photos',
},
),
migrations.CreateModel(
name='BoatModel',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('boat_name', models.CharField(db_index=True, help_text='Please input boat model', max_length=50, unique=True, verbose_name='Boat model')),
('boat_length', models.FloatField(help_text='Please input boat water-line length', verbose_name='Boat water-line length')),
('boat_description', models.TextField(blank=True, help_text='Please describe the boat', verbose_name='Boat description')),
('boat_mast_type', models.CharField(choices=[('SL', 'Sloop'), ('KE', 'Ketch'), ('YA', 'Yawl'), ('CK', 'Cat Ketch')], default='SL', help_text='Please input boat rigging type', max_length=10, verbose_name='Boat rigging type')),
('boat_price', models.PositiveSmallIntegerField(help_text='Please input boat price', verbose_name='price of the boat')),
('boat_country_of_origin', models.CharField(help_text="Please specify boat's country of origin", max_length=20, verbose_name='Boat country of origin')),
('boat_sailboatdata_link', models.URLField(blank=True, help_text='Please type in URL to Sailboatdata page for this boat', max_length=100, verbose_name='URL to Sailboatdata')),
('boat_keel_type', models.CharField(help_text="Please specify boat's keel type", max_length=50, verbose_name='Boat keel type')),
('boat_publish_date', models.DateTimeField(auto_now_add=True)),
('boat_primary_photo', models.ImageField(help_text='Please attach a primary photo of the boat', upload_to='photos/', verbose_name='Boat primary photo')),
],
options={
'verbose_name': 'Boats primary data',
'verbose_name_plural': 'Boats primary data',
'ordering': ['boat_name'],
},
),
migrations.AddField(
model_name='boatimage',
name='boat',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='boats.BoatModel', verbose_name='Boat ForeignKey'),
),
]
解决方案
推荐阅读
- sql - 将 Int 列作为分钟添加到时间戳
- corda - 是否使用 devMode=false 禁用了节点的 CRaSH shell?
- python - Python 3:为什么在我的情况下 print (..., end=" ", flush=True) 不能用于输出覆盖?
- micronaut - 支持模板语言?
- python - 将 win32com Outlook 附件直接保存到变量
- python - 如何使用 Selenium (Python) 获取 AJAX URL?
- python - 如何在 python 中打印 SQLite 查询的结果?
- sql - SQL 查询,您将如何编写查询来接收此答案?
- css - 如何构建一个带有按钮的 mailchimp 模板,该按钮使用将导出到 MandrillApp 的字体 Latos 而不中断?
- excel - Excel:在列中查找实例,其中两个相同的非空白单元格由连续的非空白单元格分隔