我有以下方案来创建地址表:
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();
});
出于安全考虑,“id”是一个随机生成的唯一字符串,而不是自动增量整数。
只有一个问题:Laravel使列“number”唯一,因为它是唯一具有整数数据类型的列。我们希望将列“id”作为主键和唯一键。
我们也尝试过这样做:
$table->primary('id')->index();
$table->uuid('id')->index();
$table->string('id')->primary()->index();
我仍然遇到这个错误:
完整性约束冲突:19个唯一性约束失败:
地址.number