Mar*_*ten 8 php database-schema laravel laravel-5.2
我有以下用于创建地址表的模式:
Schema::create('addresses', function (Blueprint $table) {
$table->string('id')->index();
$table->string('street', 100);
$table->integer('number', 5);
$table->string('addition', 10);
$table->string('postal_code', 7);
$table->string('place', 45);
$table->string('country', 45);
$table->timestamps();
$table->softDeletes();
});
Run Code Online (Sandbox Code Playgroud)
出于安全原因,'id'是随机生成的唯一字符串,而不是自动增量整数.
只有一个问题:Laravel使列'数'唯一,因为它是唯一一个数据类型为整数的列.我们希望列'id'作为主键和唯一键.
我们也试过这个:
$table->primary('id')->index();
$table->uuid('id')->index();
$table->string('id')->primary()->index();
Run Code Online (Sandbox Code Playgroud)
我仍然收到这个错误:
完整性约束违规:19 UNIQUE约束失败:
addresses.number
这对我有用:
Schema::create('addresses', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->integer('number', false);
});
Run Code Online (Sandbox Code Playgroud)