- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经使用 Django 大约 2 年了,有一个功能我一直害怕使用:伪造迁移 .
我几乎到处都看过,我能得到的最多信息来自 documentation它指出:
--假
Tells Django to mark the migrations as having been applied or unapplied, but without actually running the SQL to change your database schema.
This is intended for advanced users to manipulate the current migration state directly if they’re manually applying changes; be warned that using --fake runs the risk of putting the migration state table into a state where manual recovery will be needed to make migrations run correctly.
Allows Django to skip an app’s initial migration if all database tables with the names of all models created by all CreateModel operations in that migration already exist. This option is intended for use when first running migrations against a database that preexisted the use of migrations. This option does not, however, check for matching database schema beyond matching table names and so is only safe to use if you are confident that your existing schema matches what is recorded in your initial migration.
makemigrations
的状态将无法正常工作。
最佳答案
如果您需要合并具有相似模型的两个分支或在它们之间切换,则它与类似于源代码(git)中的合并冲突的数据库问题有关。没有人故意喜欢它。
想象一下,您上周开始修改一个应用程序,可能是因为您发现了一个错误,或者您通过字段或表扩展了应用程序。今天您收到一个更新,但遇到了问题,因为有一个迁移添加了一个仍在您的数据库中的字段,您只能应用该迁移的其他部分。您通过运行查看迁移的 SQL 内容
./manage sqlmigrate some_app 0007_new_migration >customized-some_app-0007_new_migration.sql
将内容与上周所做的更改进行比较,并删除或注释掉仍然适用且无法重复的命令。手动运行所有剩余的 SQL。标记该迁移,就像它会自动应用一样:
./manage migrate --fake some_app 0007_new_migration
如果您破坏了某些东西,可能没有人可以帮助您,因为迁移系统不会更多地了解数据库的当前状态。因此做一个备份,写笔记,使用沙箱并精确工作。
django_migrations
是在所有应用程序中应用的迁移的简单列表。此表中的行应始终与数据库结构处于同步状态。可以通过正常的
migrate
应用迁移. (或未通过反向迁移应用到旧状态,当然通常会丢失一些数据)假迁移仅将更改应用于 django_migrations 表。
me => select * from django_migrations;
id | app | name | applied
----+----------+-------------------------+-------------------------------
1 | some_app | 0001_initial | 2017-10-16 06:11:07.31249+02
2 | some_app | 0002_auto_20171016_1905 | 2017-10-17 02:05:48.979295+02
迁移(文件)是增量更改的描述,也是评估
models.py
之间差异的可能信息。自上次迁移以来,在运行
makemigrations
时进行比较.在某些表最初未受管理并且以后可以被管理的情况下,这也足够了。 (因此也记录了非托管表。)
sqlmigrate
与
--fake
可用于
fix a broken database by migrations (重新创建已删除的表)。
migrate
重新创建它们(请注意并查看下面我的评论),您可能还想首先通过伪迁移名称“
零 ”重置该应用程序的所有迁移,包括初始迁移。
./manage migrate --fake some_app zero
.
关于Django migrate --fake 和 --fake-initial 解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46772762/
因此,我正在使用 rails(ruby 1.9.3p392、rails 3.2、sqlite3 db)并尝试将无处不在的博客教程代码部署到“生产”服务器(apache、passenger、ubuntu
我继承了一个项目,该项目设置为使用 Entity Framework 在新数据库上设置数据库架构。 该项目最初有两个不同的文件夹——默认的/Migrations 文件夹和另一个文件夹——带有 DbMi
我在我的 Nest 应用程序上运行这行代码: import * as typeOrm from "../node_modules/typeorm/index"; bootstrap(){ //
我需要像下面的代码一样创建一个外键: Create.ForeignKey().FromTable("TCGDocFiscalOpMedItem").ForeignColumn("IDCabecalho
如何从扩展 Migration 的类的 Up(或 Down)方法中获取迁移正在操作的数据库的名称 public class BaseMigration : Migration { public
我们已将迁移添加到我们的xamarin表单项目中,此后我们就无法将其部署到iOS设备上。它可以在模拟器上正常运行,但在部署到设备时会因AOT错误而失败。 这似乎是一个在网络上广泛传播的话题,但是到目前
我正在尝试自己研究 Fluent Migrator,但我遇到了一个问题,我需要更改由 Fluent Migrator 创建的表的结构,这意味着我使用以下代码创建了一个名为 user 的表 [Migr
我正在使用 PostgreSQL、Rails 3.1.3 和 Ruby 1.9.3。我正在努力使用 db:migrate 概述 here . 这是我在终端中看到的: funkdified@funkdi
我决定使用 gorm作为我的 ORM。我想使用 golang-migrate/migrate 进行迁移因为,看起来 GORM 没有版本化迁移文件。我宁愿使用 CLI 进行迁移,而不是使用自动迁移。 我
我正在针对现有 SQL Server 数据库设置 EF Core 3.1.3 迁移。 这是我到目前为止所做的: 从现有数据库搭建我的模型。 添加 InitialCreate 迁移。 删除 Initia
我正在玩 Entity Framework 和持续构建。到目前为止,通过使用 migrate.exe 和适当的参数,我能够毫无问题地运行迁移或一系列迁移。 但是,我在尝试让 migrate.exe 踢
我正在使用包管理器控制台向我的数据库添加迁移,但由于某种原因它只是卡住并且什么也不做。停止它并继续使用它的唯一方法是使用任务管理器关闭 Visual Studio。这是一个已知问题吗? 最佳答案 我不
我在sequelize上运行帮助命令,发现有两个不同的命令具有相同的描述: $ sequelize help:migration:create Sequelize [Node: 6.9.5, CLI:
在这里,我使用的是 Microsoft Azure。 其中,我正在尝试使用开源 DocumentDB 数据迁移工具将数据从各种来源导入 Microsoft Azure DocumentDB,包括 JS
我是 Laravel 的新手。 我正在开发 Laravel 版本 6。 我已经创建了迁移。 第一次运行良好,但如果我更改迁移文件中的某些内容,然后运行 php artisan migrate它显示
我已经使用 NuGet 安装了 Migrator.NET,但是当我尝试使用 MSBuild 运行迁移时,出现以下错误。我看到它在访问 Migrator.Framework 程序集时遇到问题,但我不确定
我有一个基于 miguel flask tutorial 的网络应用程序 所以我将 sqlalchemy-migrate 用于数据库,现在我应该在迁移中使用 Alembic 我该如何配置?有什么方法可
我已经尝试执行 cli 命令 ./doctrine generate-migrations-diff 并在正确的文件夹中正确创建了一个版本文件。 消息是:generate-migrations-dif
可以定义存储迁移的多个路径: doctrine_migrations.yaml doctrine_migrations: migrations_paths: 'App\Migr
我在我的 .Net 应用程序中使用 Fluent Migrator 1.6.2。 对于数据库的上迁移或下迁移,需要通过命令行传递汇编文件(迁移类所在的数据库工程的dll文件)来执行Migrate.ex
我是一名优秀的程序员,十分优秀!