the error you are getting is coming from your idea migration , let your category migration come first before the idea migration then try seeding again
Oct 11, 2021
7
Level 12
Can't run seed on heroku
I tried to run heroku run -a playazchoice php artisan migrate:fresh --seed on the Heroku CLI but it's not letting me, why?
In Connection.php line 703:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`heroku_74d4fb1
9f97e161`.`ideas`, CONSTRAINT `ideas_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`)) (SQL: insert into
`ideas` (`user_id`, `category_id`, `title`, `description`, `slug`, `updated_at`, `created_at`) values (5, 4, Itaque Molestiae Et Natus
, Quas nesciunt fugit explicabo. Odio rem qui dolorum adipisci minus et. Sint laborum ut quidem ratione quia assumenda est. Doloremque
labore dolor quia neque cupiditate. Totam qui laboriosam doloribus non facilis placeat harum. Nesciunt magni aut nobis sed. In magnam a
ccusamus sit qui aperiam rerum., itaque-molestiae-et-natus, 2021-10-11 22:07:35, 2021-10-11 22:07:35))
In Connection.php line 492:
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`heroku_74d4fb1
9f97e161`.`ideas`, CONSTRAINT `ideas_category_id_foreign` FOREIGN KEY (`category_id`) REFERENCES `categories` (`id`))
Also when I was testing this:
/** @test */
public function list_of_ideas_show_on_main_page()
{
$categoryOne = Category::factory()->create(['name' => 'Category 1']);
$categoryTwo = Category::factory()->create(['name' => 'Category 2']);
$ideaOne = Idea::factory()->create([
'title' => 'My First Idea',
'category_id' => $categoryOne->id,
'description' => 'Description of my first idea',
]);
$ideaTwo = Idea::factory()->create([
'title' => 'My Second Idea',
'category_id' => $categoryTwo->id,
'description' => 'Description of my second idea',
]);
$response = $this->get(route('idea.index'));
$response->assertSuccessful();
$response->assertSee($ideaOne->title);
$response->assertSee($ideaOne->description);
$response->assertSee($categoryOne->name);
$response->assertSee($ideaTwo->title);
$response->assertSee($ideaTwo->description);
$response->assertSee($categoryTwo->name);
}
I had this error:
1) Tests\Feature\ShowIdeasTest::single_idea_shows_correctly_on_the_show_page
Illuminate\Database\QueryException: SQLSTATE[23000]: Integrity constraint violation: 19 FOREIGN KEY constraint failed (SQL: insert into "ideas" ("user_id", "category_id", "title", "description", "slug", "updated_at", "created_at") values (1, 2, My First Idea, Description of my first idea, my-first-idea, 2021-10-11 21:50:52, 2021-10-11 21:50:52))
Please or to participate in this conversation.