【发布时间】:2018-02-21 05:01:53
【问题描述】:
我正在 Laravel 5.4 中进行一些数据库迁移。迁移与 MySQL 数据库一起工作正常,但为了测试我想使用 SQLite 但迁移失败。这是代码
public function up()
{
Schema::create('mapped_venues', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('upload_job_id')->nullable();
$table->string('venue')->default('');
$table->unsignedInteger('venue_id')->nullable();
$table->timestamps();
$table->index(['venue']);
});
Schema::create('mapped_teams', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('upload_job_id')->nullable();
$table->string('team')->default('');
$table->unsignedInteger('team_id')->nullable();
$table->timestamps();
$table->index(['team']);
});
}
当我运行php artisan migrate 时,mapped_teams.team 列上的索引没有创建,但mapped_venues.venue 上的索引是!!
$ sqlite3 database/database.sqlite
SQLite version 3.19.3 2017-06-08 14:26:16
Enter ".help" for usage hints.
sqlite> .indexes mapped_teams
sqlite> .indexes mapped_venues
mapped_venues_venue_index
sqlite>
我也尝试在单独的调用中创建索引
Schema::table('mapped_venues', function (Blueprint $table) {
$table->index(['venue']);
});
Schema::table('mapped_teams', function (Blueprint $table) {
$table->index(['team']);
});
但结果是一样的。有趣的是,当我(错误地)将索引$table->index['team']) 的创建留在创建表的调用中时(因此,我有两个创建索引的调用)我得到索引mapped_teams_team_index 已经存在的错误。
我正在使用:
- Laravel 5.4.36
- Doctrine DBal 2.6.2
- SQLite 3.19.3
【问题讨论】:
标签: php laravel sqlite database-migration