lundi 19 juillet 2021

Seeding a pivot table in heroku results to error

I'm deploying a Laravel 5.2 application with a database in Heroku. I've managed to migrate my tables without errors until it's time to seed the tables. The seeding always resulted in an error which is this:

Seeded: RolesTableSeeder
Seeded: PrivilegesTableSeeder
[2021-07-19 18:40:57] production.ERROR: PDOException: SQLSTATE[42703]: Undefined column: 7 ERROR:  column "id" does not exist
LINE 1: ..." ("role_id", "privilege_id") values ($1, $2) returning "id"
                                                                   ^ in /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:335
Stack trace:
#0 /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(335): PDOStatement->execute()
#1 /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(722): Illuminate\Database\Connection->Illuminate\Database\{closure}()
#2 /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(685): Illuminate\Database\Connection->runQueryCallback()
#3 /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(349): Illuminate\Database\Connection->run()
#4 /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(312): Illuminate\Database\Connection->select()
#5 /app/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/PostgresProcessor.php(20): Illuminate\Database\Connection->selectFromWriteConnection()
#6 /app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2107): Illuminate\Database\Query\Processors\PostgresProcessor->processInsertGetId()
#7 [internal function]: Illuminate\Database\Query\Builder->insertGetId()
#8 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1423): call_user_func_array()
#9 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1628): Illuminate\Database\Eloquent\Builder->__call()
#10 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1597): Illuminate\Database\Eloquent\Model->insertAndSetId()
#11 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1488): Illuminate\Database\Eloquent\Model->performInsert()
#12 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(574): Illuminate\Database\Eloquent\Model->save()
#13 /app/database/seeds/RolePrivilegesTableSeeder.php(33): Illuminate\Database\Eloquent\Model::create()
#14 /app/database/seeds/RolePrivilegesTableSeeder.php(17): RolePrivilegesTableSeeder->addPrivilege()
#15 /app/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(39): RolePrivilegesTableSeeder->run()
#16 /app/database/seeds/DatabaseSeeder.php(17): Illuminate\Database\Seeder->call()
#17 /app/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(63): DatabaseSeeder->run()
#18 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2314): Illuminate\Database\Console\Seeds\SeedCommand->Illuminate\Database\Console\Seeds\{closure}()
#19 /app/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(64): Illuminate\Database\Eloquent\Model::unguarded()
#20 [internal function]: Illuminate\Database\Console\Seeds\SeedCommand->fire()
#21 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array()
#22 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call()
#23 /app/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute()
#24 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run()
#25 /app/vendor/symfony/console/Application.php(794): Illuminate\Console\Command->run()
#26 /app/vendor/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand()
#27 /app/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun()
#28 /app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run()
#29 /app/artisan(35): Illuminate\Foundation\Console\Kernel->handle()
#30 {main}

Next Illuminate\Database\QueryException: SQLSTATE[42703]: Undefined column: 7 ERROR:  column "id" does not exist
LINE 1: ..." ("role_id", "privilege_id") values ($1, $2) returning "id"
                                                                   ^ (SQL: insert into "role_privileges" ("role_id", "privilege_id") values (1, 1) returning "id") in /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php:729
Stack trace:
#0 /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(685): Illuminate\Database\Connection->runQueryCallback()
#1 /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(349): Illuminate\Database\Connection->run()
#2 /app/vendor/laravel/framework/src/Illuminate/Database/Connection.php(312): Illuminate\Database\Connection->select()
#3 /app/vendor/laravel/framework/src/Illuminate/Database/Query/Processors/PostgresProcessor.php(20): Illuminate\Database\Connection->selectFromWriteConnection()
#4 /app/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php(2107): Illuminate\Database\Query\Processors\PostgresProcessor->processInsertGetId()
#5 [internal function]: Illuminate\Database\Query\Builder->insertGetId()
#6 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php(1423): call_user_func_array()
#7 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1628): Illuminate\Database\Eloquent\Builder->__call()
#8 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1597): Illuminate\Database\Eloquent\Model->insertAndSetId()
#9 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(1488): Illuminate\Database\Eloquent\Model->performInsert()
#10 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(574): Illuminate\Database\Eloquent\Model->save()
#11 /app/database/seeds/RolePrivilegesTableSeeder.php(33): Illuminate\Database\Eloquent\Model::create()
#12 /app/database/seeds/RolePrivilegesTableSeeder.php(17): RolePrivilegesTableSeeder->addPrivilege()
#13 /app/vendor/laravel/framework/src/Illuminate/Database/Seeder.php(39): RolePrivilegesTableSeeder->run()
#14 /app/database/seeds/DatabaseSeeder.php(17): Illuminate\Database\Seeder->call()
#15 /app/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(63): DatabaseSeeder->run()
#16 /app/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php(2314): Illuminate\Database\Console\Seeds\SeedCommand->Illuminate\Database\Console\Seeds\{closure}()
#17 /app/vendor/laravel/framework/src/Illuminate/Database/Console/Seeds/SeedCommand.php(64): Illuminate\Database\Eloquent\Model::unguarded()
#18 [internal function]: Illuminate\Database\Console\Seeds\SeedCommand->fire()
#19 /app/vendor/laravel/framework/src/Illuminate/Container/Container.php(507): call_user_func_array()
#20 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(169): Illuminate\Container\Container->call()
#21 /app/vendor/symfony/console/Command/Command.php(256): Illuminate\Console\Command->execute()
#22 /app/vendor/laravel/framework/src/Illuminate/Console/Command.php(155): Symfony\Component\Console\Command\Command->run()
#23 /app/vendor/symfony/console/Application.php(794): Illuminate\Console\Command->run()
#24 /app/vendor/symfony/console/Application.php(186): Symfony\Component\Console\Application->doRunCommand()
#25 /app/vendor/symfony/console/Application.php(117): Symfony\Component\Console\Application->doRun()
#26 /app/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(107): Symfony\Component\Console\Application->run()
#27 /app/artisan(35): Illuminate\Foundation\Console\Kernel->handle()
#28 {main}



  [Illuminate\Database\QueryException]
  SQLSTATE[42703]: Undefined column: 7 ERROR:  column "id" does not exist
  LINE 1: ..." ("role_id", "privilege_id") values ($1, $2) returning "id"
                                                                     ^ (SQL:
  insert into "role_privileges" ("role_id", "privilege_id") values (1, 1) ret
  urning "id")



  [PDOException]
  SQLSTATE[42703]: Undefined column: 7 ERROR:  column "id" does not exist
  LINE 1: ..." ("role_id", "privilege_id") values ($1, $2) returning "id"
                                                                     ^

I've tried setting the $primary_key to null and one of the id columns in the pivot table but it always returns this error.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire