//public function up(): void
{
Schema::create('comentarios', function (Blueprint $table) {
$table->id();
$table->text('contenido');
$table->timestamp('fechacreacion')->default(now());
$table->timestamps();
$table->foreignId('idUsuario')->constrained('usuarios');
$table->foreignId('idReceta')->constrained('recetas');
});
}
public function up(): void
{
Schema::create('usuarios', function (Blueprint $table) {
$table->id();
$table->string('nombreCompleto', 255);
$table->string('apodo', 255);
$table->string('correo', 255);
$table->string('contrasena', 255);
$table->timestamp('fechaCreacion')->default(now());
$table->tinyInteger('esAdmin')->default(0);
$table->string('genero', 50)->nullable();
$table->string('fotoPerfil', 255)->nullable();
$table->enum('experiencia', ['amateur', 'experimentado', 'chef']);
});
}
it keeps telling me that the relation between tables its wrong tho i dont see anything wrong
#migration problems
23 messages · Page 1 of 1 (latest)
Mind explaining what the problem is? Would make it a lot easier to pinpoint where to look at
yes
public function up(): void
{
Schema::create('comentarios', function (Blueprint $table) {
$table->id();
$table->unsignedBigInteger('idUsuario');
$table->unsignedBigInteger('idReceta');
$table->text('contenido');
$table->timestamp('fechacreacion')->default(now());
$table->foreign('idUsuario')->references('id')->on('usarios');
$table->foreign('idReceta')->references('id')->on('receta');
$table->timestamps();
});
}
public function up()
{
Schema::create('usuarios', function (Blueprint $table) {
$table->id();
$table->string('nombreCompleto', 255);
$table->string('apodo', 255);
$table->string('correo', 255);
$table->string('contrasena', 255);
$table->timestamp('fechaCreacion')->default(now());
$table->tinyInteger('esAdmin')->default(0);
$table->string('genero', 50)->nullable();
$table->string('fotoPerfil', 255)->nullable();
$table->enum('experiencia', ['amateur', 'experimentado', 'chef']);
});
}
That's not an explanation, that's just dumping more code
it says foreign key are wrong
so i needed to send the tables
to show them
comentarios should have 2 fk, from usuarios and from recetas
So, what is the actual error..?
but when it tries to create the table it says fk are wrong
SQLSTATE[HY000]: General error: 1005 Can't create table `foroplatos2`.`comentarios` (errno: 150 "Foreign key constraint is incorrectly formed") (Connection: mysql, SQL: alter table `comentarios` add constraint `comentarios_idusuario_foreign` foreign key (`idUsuario`) references `usarios` (`id`))
this one
Probably because the types don't match, difficult to read tho
$table->id(); => $table->unsignedBigInteger('idUsuario');
And on which Laravel version is this?
10.40