【发布时间】:2015-05-12 22:27:45
【问题描述】:
这些是我的要求:
- 我有一张桌子(
upload_training_files) - 字段为
id、organisation_id(外)、year_id(外)、created_by、created_at、updated_by、updated_at、file_path。 -
organisation_id字段是指organisations的id字段。它应该是auto_incremented,并且应该用一个序列表(upload_training_file_organisation_id_fk_seq)来标识。
经过多次尝试,我在 Laravel 中未能做到这一点。这是我的架构:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUploadTrainingFileTable extends Migration {
public function up()
{
Schema::create('upload_training_file', function(Blueprint $table) {
$table->bigincrements('id');
$table->biginteger('organisation_id_fk')->unsigned()->unique();
$table->foreign('organisation_id_fk')->references('organisation_id')->on('organisations');
$table->biginteger('year_id_fk')->unsigned()->unique();
$table->foreign('year_id_fk')->references('year_id')->on('year_of_performance');
$table->biginteger('created_by')->nullable();
$table->time('created_at')->nullable();
$table->biginteger('updated_by');
$table->time('updated_at')->nullable();
$table->string('file_path')->nullable();
});
}
public function down()
{
Schema::drop('upload_training_file');
}
}
这是数据库表的快照
【问题讨论】:
标签: postgresql laravel schema sequence