2
I would like to create a double primary key with an auto increment field "id" and the "term", but it gives error and I do not know the correct way to do, if anyone can help me, I would appreciate it very much!
Migrate
Schema::create('disciplinas', function (Blueprint $table) {
$table->increments('id');
$table->integer('periodo_letivos_id')->unsigned();
$table->foreign('periodo_letivos_id')
->references('id')
->on('periodo_letivos')
->onDelete('cascade');
$table->integer('cursos_id')->unsigned();
$table->foreign('cursos_id')
->references('id')
->on('cursos')
->onDelete('cascade');
$table->integer('periodo_regular')->nullable();
$table->string('matriz_curricular')->nullable();
$table->string('nome', 200);
$table->string('abrev_nome', 15);
$table->integer('professors_id')->unsigned();
$table->foreign('professors_id')
->references('id')
->on('professors')
->onDelete('cascade');
$table->string('aulas', 3)->nullable();
$table->string('aulas_hora', 3)->nullable();
$table->string('obs', 400)->nullable();
$table->primary(['id', 'periodo_letivos_id']);
$table->timestamps();
$table->softDeletes();
});
Try using $table->unsignedInteger('periodo_letivo_id');
– AnthraxisBR
I tried, but it didn’t work, I needed this field to be auto increment too. For example I cannot insert the same discipline in the same period 2 times!
– Ulisses Gimenes
Have you checked whether the two fields are in exactly the same typing ? int unsignd
– AnthraxisBR
So, if I leave $table->increments('id')->unsigned(); and $table->integer('periodo_letivos_id')->unsigned(); both as unsigned and $table->Primary(['id', 'periodo_letivos_id']); it doesn’t work, but if I put id as integer and unsigned accepts but then I miss auto-registration!
– Ulisses Gimenes
And if you leave the unsigned ones, I did right on the table, but this way it’s to work
– AnthraxisBR
He did not accept to add the constrait of academic periods without being unsigned!
– Ulisses Gimenes
Your bank is on which engine ? Myisam or Innodb
– AnthraxisBR
I am using Mysql as vejoqual engine?
– Ulisses Gimenes
I decided to leave the id without increment, will help me create a Rigger that works?
– Ulisses Gimenes
I need to create an auto increment
– Ulisses Gimenes
Try putting this in shchema of the table: $table->engine = 'Innodb', if not solve ai movo pro chat para gente tentar resolver
– AnthraxisBR
It didn’t work either, I’m trying to create a Rigger but it’s not working!
– Ulisses Gimenes
I solved otherwise, I changed the fields to unsigned and after creation I turned a command and changed the id structure to auto increment! wait for when to start the consultations to know
– Ulisses Gimenes
Great, if it doesn’t work, revisit the topic kk
– AnthraxisBR