0
Schema::create('filiais', function (Blueprint $table) {
$table->id();
$table->string('filial', 30);
$table->timestamps();
});
Schema::create('produto_filiais', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('filial_id');
$table->unsignedBigInteger('produto_id');
$table->decimal('preco_venda', 8, 2);
$table->integer('estoque_minimo', 8, 2);
$table->integer('estoque_maximo', 8, 2);
$table->timestamps();
$table->foreign('filial_id')->references('id')->on('filiais');
$table->foreign('produto_id')->references('id')->on('produtos');
});
Schema::table('produtos', function (Blueprint $table) {
$table->dropColumn(['preco_venda', 'estoque_minimo', 'estoque_maximo']);
});
After rotating the php artisan migrate
, he makes the following mistake:
SQLSTATE[42000]: Syntax error or access Violation: 1075 Incorrect table Definition; there can be only one auto column and it must be defined as a key (SQL: create table
produto_filiais
(id
bigint unsigned not null auto_increment Primary key,filial_id
bigint unsigned not null,produto_id
bigint unsigned not null,preco_venda
decimal(8, 2) not null,estoque_minimo
int unsigned not null auto_increment Primary key,estoque_maximo
int unsigned not null auto_increment Primary key,created_at
timestamp null,updated_at
timestamp null) default Character set utf8mb4 collate 'utf8mb4_unicode_ci')
the message is very clear "there can be only one auto column and it must be defined as a key", in free translation "there may be only one automatic column and should be set as a key"
– Ricardo Pontual
If you wish to use primary key auto increment see https://laravel.com/docs/8.x/migrations#column-method-increments and https://laravel.com/docs/8.x/migrations#column-method-bigIncrements
– Marcos Xavier