【发布时间】:2021-02-13 00:54:07
【问题描述】:
这是create_facts_table 的样子:
class CreateFactsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::connection('pgsql')->create('facts', function (Blueprint $table) {
$table->bigInteger('entry_id');
$table->string('tag');
$table->timestampTz('time');
$table->double('sensor_value');
$table->index(['entry_id', 'tag', 'time']);
$table->unique(['entry_id', 'tag', 'time']);
});
DB::connection('pgsql')->statement('SELECT create_hypertable(\'facts\', \'time\');');
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Tried both, neither would delete the table
Schema::connection('pgsql')->dropIfExists('facts');
//DB::connection('pgsql')->statement('DROP TABLE facts;');
}
}
我没有收到来自down() 的任何错误。我能够以.env 文件中指定的数据库用户身份登录并运行DROP TABLE facts。
当我运行php artisan migration:fresh up() 无法创建表并抛出重复表错误:
Duplicate table: 7 ERROR: relation "facts" already exists
手动删除表后,我可以运行php artisan migration:fresh。我必须指定connection('pgsql'),因为我正在使用多个数据库。半无关,但我正在使用 TimeScaleDB 扩展(因此create_hypertable())
【问题讨论】:
标签: laravel