
Juanito Ortega Guzmán
PreguntaMe pasa algo extraño:
Primero al ejecutar php artisan migrate se crearon las tablas sin problemas, pero al ejecutar: php artisan migrate:fresh --seed
Me salieron mensajes de error indicando que los campos image y description no tenian un valor por defecto.
Le añadí esto a las migraciones:
$table->string('image')->nullable(); $table->text('description')->nullable();
Ejecuté otra vez php artisan migrate:fresh --seed y me arroja este error:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`livewire`.`posts`, CONSTRAINT `posts_course_id_foreign` FOREIGN KEY (`course_id`) REFERENCES `courses` (`id`)) (SQL: insert into `posts` (`name`, `free`, `course_id`, `updated_at`, `created_at`) values (Quidem modi eveniet a voluptas deserunt quasi., 1, 0, 2021-05-27 20:14:06, 2021-05-27 20:14:06))
No entiendo qué sucede aquí, tengo todo correctamente instalado.
Ayuda por favor. Gracias

Arturo Alejandro Buentello Gutiérrez
Perece estar fallando el constraint hacia el curso ¿el curso existe antes de que crees el post?

Juanito Ortega Guzmán
Hola Arturo Tenía 2 errores 1.- En la migración de posts había dejado por error:
$table->string('name'); $table->string('slug'); $table->string('image'); <----- Me olvidé borrar estas 2 lineas que las copié como modelo de la migracion de courses $table->text('description'); <----
2.- Y el otro error:
return [ 'name' => $this->faker->sentence, 'free' => rand(0,1), 'course_id' => rand(1,10), // Aquí en lugar de 1 a 10, había puesto de 0 a 10 ];
Saludos.

David Alejandro Ayala Rizo
Me pasa lo mismo :/