Django 迁移卡住了

2024-02-15

我有一个新字段要添加到我的数据库中。所以我说

python manage.py makemigrations

这正确地创建了kernel/migrations/0003_auto_20150726_1911.py。我检查了内容,一切看起来都很好。

I say

python manage.py migrate

我不太高兴。文件kernel/migrations/0002_auto_20150707_1459.py,这会添加字段date_of_birth到餐桌userprofile,失败。尽管我很确定迁移已应用。因此迁移 0003 永远不会被应用。

这就是生产。 :( 我完全不知道该怎么做才能应用 0003 而不是软管 django。建议?

其余部分是支持文档:

迁徙

╭╴ (master=) [virt]╶╮
╰ [T] django@beta13:migrations $ cat 0002_auto_20150707_1459.py 
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
    ('kernel', '0001_initial'),
]

operations = [
    migrations.AlterField(
    model_name='userprofile',
    name='date_of_birth',
    field=models.DateField(null=True, blank=True),
    ),
]
╭╴ (master=) [virt]╶╮
╰ [T] django@beta13:migrations $ cat 0003_auto_20150726_1911.py 
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
from django.conf import settings


class Migration(migrations.Migration):

dependencies = [
    migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ('kernel', '0002_auto_20150707_1459'),
]

operations = [
    migrations.AddField(
    model_name='trippending',
    name='requesting_user',
    field=models.ForeignKey(default=1, related_name='trippending_requesting', to=settings.AUTH_USER_MODEL),
    preserve_default=False,
    ),
    migrations.AddField(
    model_name='userprofile',
    name='can_see_pending_trips',
    field=models.BooleanField(default=False),
    ),
]
╭╴ (master=) [virt]╶╮
╰ [T] django@beta13:migrations $ 

错误

(该网站以法语运行,但我认为该错误无论如何都是明确的。)

╭╴ (master %=) [virt]╶╮
╰ [T] django@beta13:django $ python manage.py migrate
Operations to perform:
  Synchronize unmigrated apps: staticfiles, messages, admindocs
  Apply all migrations: admin, sessions, custom_user, auth, kernel, contenttypes, registration, sites
Synchronizing apps without migrations:
  Creating tables...
Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying kernel.0002_auto_20150707_1459...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
  File "/src/django/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
  File "/src/django/venv/lib/python3.4/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/src/django/venv/lib/python3.4/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
  File "/src/django/venv/lib/python3.4/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
  File "/src/django/venv/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 221, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 110, in migrate
self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/migrations/executor.py", line 147, in apply_migration
state = migration.apply(state, schema_editor)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/migrations/migration.py", line 115, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/migrations/operations/fields.py", line 201, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 484, in alter_field
old_db_params, new_db_params, strict)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 571, in _alter_field
old_default = self.effective_default(old_field)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 211, in effective_default
default = field.get_db_prep_save(default, self.connection)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 710, in get_db_prep_save
prepared=False)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 1322, in get_db_prep_value
value = self.get_prep_value(value)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 1317, in get_prep_value
return self.to_python(value)
  File "/src/django/venv/lib/python3.4/site-packages/django/db/models/fields/__init__.py", line 1287, in to_python
params={'value': value},
django.core.exceptions.ValidationError: ["Le format de date de la valeur «\xa0\xa0» n'est pas valide. Le format correct est AAAA-MM-JJ."]
╭╴ (master %=) [virt]╶╮
╰ 1,[T] django@beta13:django $ 

The data

我检查了 postgres,希望能发现一些问题。但一切看起来都很好。

mydb=# select date_of_birth from kernel_userprofile;
 date_of_birth 
---------------
 2018-10-23
 1972-05-31
 1978-10-21
 2008-12-29
 1967-08-26
 2015-07-26
(6 rows)

mydb=#

对于社区来说,问题是django_migrations表未更新为0002_auto_20150707_1459即使迁移实际上应用于table正如帖子中提到的。

解决方案是插入一个新行django_migrations表的数据如下所示,以便迁移0002被跳过。

INSERT INTO DJANGO_MGRATIONS ('app', 'name', 'applied') VALUES ('appname', '0002_auto_20150707_1459', '2015-07-07 00:00')

跳过迁移必须极其谨慎,因此在跳过之前检查所有详细信息。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Django 迁移卡住了 的相关文章

随机推荐

  • JasperReports 可以在报告中包含 pdf 吗?

    是否可以在 JasperReport 中包含现有的 pdf 文件 我们确实希望将新数据附加到现有报告中 而不重新生成现有报告 我们将导出回 pdf 我正在考虑使用 iText 的 PdfCopy 来合并两个 pdf 但希望 JasperRe
  • 通过联合访问 __m128 变量的字节是否合法?

    考虑这个变量声明 union struct float x y z padding components m128 sse data 我的想法是通过分配值x y z字段 执行 SSE2 计算并通过读取结果x y z 不过 我对这是否合法有些
  • 检索 Windows Vista 及更高版本上 BootMgr 的分区号

    我需要将启动管理器映射到分区号 Manufacturer Recovery partition Partition 0 Boot manager Partition 1 C Partition 2 D Partition 3 对于已安装的分
  • 在 R 中转换 3D 数组中的表格

    我有一个矩阵 R gt pippo m 1 2 3 4 1 1 2 3 4 2 5 6 7 8 3 9 10 11 12 4 13 14 15 16 5 17 18 19 20 6 21 22 23 24 我想用 dim 2 4 3 将该矩
  • 如何调试 UWP UpdateTask?

    在我的 UWP 应用中 如何通过 UpdateTask 中的代码进行调试 VS 2017 中的 生命周期事件 下拉菜单似乎没有提供触发此类后台任务的选择 有办法做到这一点吗 首先介绍一下 UWP 的 UpdateTask 这是一个后台任务
  • facebook-ios-sdk requestWithGraphPath:@"我/朋友"

    我找不到关于这个 sdk 的任何基本文档 我只是愚蠢还是找错地方了 我不知道这个方法是什么 void request FBRequest request didLoad id result 实际上在这样的请求的情况下返回 requestWi
  • Bootstrap tabbable 和 popover 之间的冲突

    我正在尝试在同一页面中使用 Twitter Bootstrap tabbable 和 Bootstrap popovers 我在解决弹出窗口无法出现在选项卡限制之外的问题时遇到困难 问题是当弹出窗口出现在边框旁边时 它是半隐藏的 我不是 J
  • 需要授予哪些权限才能访问 sys.dba_systems

    我正在开发适用于 Oracle 的应用程序 对于某种逻辑 我需要从给定的数据库用户获取具有指定模式的表列表 就我而言 我有一个已授予给定模式访问权限的用户 因此 当我的代码使用给定的凭据创建连接并尝试从以下查询中获取表时 它返回表列表 SE
  • Laravel 5 委托一条路由 - 根据角色加载不同的控制器

    所以我刚刚开始学习 Laravel 并且我已经实现了 Entrust Role Permission 包 效果非常好 现在我的问题是 我想要一个 仪表板 页面 如下所示 example com dashboard 问题是 我不确定如何设置
  • 如何在android中使线性布局部分透明?

    我有一个RelativeLayout含 2LinearLayouts其中一个部分覆盖另一个 我想做的一部分LinearLayout顶部透明 所以我也可以看到第二个LinearLayout 知道我有 2 张图像作为 2 张图像的背景Linea
  • bash 脚本根据文件名中的日期查找旧文件

    我正在开发一个 bash 脚本 该脚本需要根据一个变量搜索单个目录中 旧 的文件 该变量指定在超过阈值之前需要经过多少天 并且文件被标记为要执行操作 可以是任何内容 从移动到存档到删除 等等 问题是文件的修改时间与确定文件需要多久才能采取行
  • 将 gitlab 包注册表中的 python 包和其他外部索引直接包含到 setup.py 依赖项中

    The gitlab包注册表 https docs gitlab com ee user packages 可以用来publish https docs gitlab com ee user packages pypi repository
  • 如何将小程序作为应用程序运行?

    我有一个 Applet 类 我想让它作为应用程序运行 所以我编写了以下代码 public static void main String args JFrame app new JFrame Applet Container app set
  • 在 jboss 中加载 HTML 图像

    我有 HTML 页面 放在临时文件夹 WEB INF 目录之外 中 我在 HTML 页面中使用了一些图像 我也将这些图像放入临时文件夹中 然后创建了我的 war 文件 当我在 localhost 中运行该程序时 图像不会加载到 HTML 页
  • 如何在 JavaScript 中将所有对象属性设置为 null?

    我正在使用 Vue 突然使用一些计算的 cssvuetify https vuetifyjs com不管用 我声明对象的方式是 personal info 在我的模板中 我可以这样做personal info name以及每个文本输入 v
  • 在外部网络上托管 Expo 应用程序?

    我正在编写一个应用程序create react native app CRNA 为一家公司 最终 它可能会投入生产 但出于研究原因 我需要一个可以轻松部署到同事手机 Android 和 iOS 的工作原型 由于知识产权的原因 我不得在任何外
  • C#图表控件删除条形图中条形之间的空格

    I have a bar chart made with the c net chart control that looks like the following 正如您所看到的 图表上每对红色和蓝色条之间都有一个空格 有没有办法删除这些
  • Pandas 时间戳以 30 秒为单位不一致

    我试图将 pandas DatetimeIndex 或 Timestamp 舍入到最接近的分钟 但我遇到了 30 秒时间戳的问题 有些向上舍入 有些向下舍入 这似乎是交替的 有什么建议可以解决这个问题 以便 30 总是四舍五入吗 gt gt
  • 比较两个 Doctrine_Record 对象

    我如何比较两个Doctrine Record对象看看它们是否 相等 在我正在考虑的域登录中 如果两个对象具有相同的属性值 则它们相等 除了id和created at and updated at字段 a laTimestampable 我想
  • Django 迁移卡住了

    我有一个新字段要添加到我的数据库中 所以我说 python manage py makemigrations 这正确地创建了kernel migrations 0003 auto 20150726 1911 py 我检查了内容 一切看起来都