- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在使用 phinx处理新项目的迁移,现在我需要创建一个新表并向其中插入一些行,我有:
$tableStatus = $this->table('status');
$tableStatus->addColumn('code', 'string');
$tableStatus->addColumn('description', 'string');
$tableStatus->save();
这添加了新表,但我在文档中找不到如何插入行,但它似乎是可能的:
The AbstractMigration Class All Phinx migrations extend from the AbstractMigration class. This class provides the necessary support to create your database migrations. Database migrations can transform your database in many ways such as creating new tables, inserting rows, adding indexes and modifying columns.
这可能吗?我该怎么做?
最佳答案
正如 igrossiter 所指出的,有一个方法可以做到这一点,方法的名称是insert
use Phinx\Migration\AbstractMigration;
class NewStatus extends AbstractMigration
{
protected $statusId = 1234; //It'd be nice to use an entity constant instead of magic numbers, but that's up to you.
protected $statusName = 'In Progress';
/**
* Migrate Up.
*/
public function up()
{
$columns = ['id', 'name'];
$data = [[$this->statusId, $this->statusName]];
$table = $this->table('status');
$table->insert($columns, $data);
$table->saveData();
}
/**
* Migrate Down.
*/
public function down()
{
$this->execute('Delete from status where id = ' . $this->statusId);
}
}
2015 年 12 月 2 日编辑
此方法的签名将在未来的稳定版本中更改为类似
$data = [
['id' => 1, 'name' => 'foo'],
['id' => 2, 'name' => 'bar']
];
$table = $this->table('status');
$table->insert($data);
关于php - 如何编写迁移以使用 phinx 插入记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28265669/
我想同步多个数据库的状态。我想比较其中的表,并创建缺少的表和列。 Php有一个库,里面有很多数据库操作的函数:Phinx不幸的是,只有创建迁移的示例,但它没有解释如何在没有它的情况下使用它。 如何在不
我想在我的项目中安装 Phinx 数据库迁移,但是 documentation命令不起作用。一开始跑不了 php 供应商/bin/phinx 初始化 因为 phinx 不是 php 命令。好的,所以我
试图弄清楚交易在 phinx 包中是如何工作的。这是我的迁移代码,它不起作用。我使用 mysql,phinx.yml 一切正常。因此表 acme 被创建,而表 fail 失败并且在 phinxlog
当我尝试创建迁移时出现此异常,但我的迁移路径中没有花括号 [异常]您可能使用大括号在 Phinx 配置文件中定义了迁移路径,但没有使用此模式匹配目录。您需要手动创建迁移目录。 我的配置: paths:
我刚刚开始学习Phinx,我需要将列的排序规则更改为latin1_swedish_ci。我没有找到有关如何执行此操作的文档。我假设它类似于: ->addColumn('text_two', 'stri
我正在尝试使用 Phinx 迁移将外键添加到表中。我的意图是创建一个表 ('sales_order_attachment') 并添加两个外键。没有太多的 Phinx 文档,所以我还没有在互联网上或通过
正如标题所描述的那样,我正在尝试利用 phinx 进行数据库迁移,但我有 AUTO-INCREMENT 列,该列未用作主键。据我所知,这不能用 phinx 来完成。 我意识到,我可能完全没有该列,但它
我知道有几篇与此类似的帖子,但它们没有给我所需的答案。因此,我正在使用 Phinx 并尝试添加外键,但出现以下错误: General error: 1215 Cannot add foreign ke
我在迁移中使用可能包含特殊字符的字符串进行了一些简单的更新。例如: $this->execute("UPDATE `setting` SET `classname` = 'org\foo\Bar' W
你能告诉我是否可以通过 Phinx 迁移 addColumn() 方法设置整数列的显式长度吗? 文档使用 MysqlAdapter::INT_REGULAR 的限制选项,如 ['limit' => M
我正在使用 phinx处理新项目的迁移,现在我需要创建一个新表并向其中插入一些行,我有: $tableStatus = $this->table('status'); $tableStatus->ad
我在初始化期间使用 --format php 设置了 phinx。它在/config/database 文件夹中作为 database.php 每当我尝试运行迁移时,我都会收到以下错误。 文件“phi
我正在创建一个 PHP REST api,使用 PHPUnit 进行单元测试和集成测试。我正在寻找集成 phinx 进行数据库迁移(而不是自己构建迁移代码)。 其实我有两个问题: 我将如何使用 Phi
我想在使用 wamp 服务器的项目中使用“Phinx”。我能够使用 cmd 安装: 以下说明: http://docs.phinx.org/en/latest/install.html compose
我正在为我的 PHP 应用程序运行官方 MySQL Docker 容器。我正在使用 Phinx 进行迁移。 MySQL 镜像似乎工作正常,因为我可以使用 MySQL Workbench 作为“dbus
我正在使用 Phinx 进行数据库迁移。 在我的例子中,它不适用于 PostgreSQL 模式(例如 test.table)。 // create the table $table = $this->
使用 sqlite 内存的 Phinx 迁移似乎在 0.9.2 中不起作用,我有一个非常简单的应用程序,只有一个表(产品)。运行迁移后,产品表不存在: use Symfony\Component\Ya
我正在尝试使用 Phinx 将表从 db1 迁移到 db2迁移,但我有一个表有问题,我的列类型为 DOUBLE。我知道那里有受支持的类型 Phinx column type ,但可以指定 FLOAT
我已经使用了phinx迁移并使用了它的“向上”和“更改”功能,但我没有注意到它们之间有任何区别。下面是我的迁移文件。 hasTable('uss_dish')){ $d
我正在尝试使用 Phinx 创建一个 CitySeeder .但是我收到以下错误: [PDOException]
我是一名优秀的程序员,十分优秀!