I've the following schema for creating the addresses table:
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();
});
For security reasons, 'id' is an random generated and unique string instead of an auto increment integer.
Just one problem: Laravel makes the column 'number' unique, because it is the only column with data type integer. We want the column 'id' as primary and unique key.
We also tried this:
$table->primary('id')->index();
$table->uuid('id')->index();
$table->string('id')->primary()->index();
I'm still getting this error:
Integrity constraint violation: 19 UNIQUE constraint failed:
addresses.number
This worked for me:
Schema::create('addresses', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->integer('number', false);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With