public function run()
{
$this->call(UserTableSeeder::class);
$this->call(BlogCategorySeeder::class);
$users = \App\User::all();
$result = [];
foreach ($users as $user) {
$result[] = $user->id;
}
dd($result);
factory(BlogPost::class, 1)->create();
}
Dropped all tables successfully.
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table (0.06 seconds)
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table (0.06 seconds)
Migrating: 2019_08_19_000000_create_failed_jobs_table
Migrated: 2019_08_19_000000_create_failed_jobs_table (0.04 seconds)
Migrating: 2022_01_08_112050_create_blog_categories_table
Migrated: 2022_01_08_112050_create_blog_categories_table (0.06 seconds)
Migrating: 2022_01_19_192927_create_jobs_table
Migrated: 2022_01_19_192927_create_jobs_table (0.06 seconds)
Migrating: 2022_01_21_220416_create_blog_posts_table
Migrated: 2022_01_21_220416_create_blog_posts_table (0.26 seconds)
Seeding: UserTableSeeder
Seeded: UserTableSeeder (0.16 seconds)
Seeding: BlogCategorySeeder
Seeded: BlogCategorySeeder (0 seconds)
array:2 [
0 => 1
1 => 2
]
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'user_id' doesn't exist in table (SQL: alter table `blog_posts` add constraint `blog_posts_user_id_foreign` foreign key (`user_id`) references `users` (`id`))
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
+12 vendor frames
13 database/migrations/2022_01_08_112722_create_blog_posts_table.php:26
Illuminate\Support\Facades\Facade::__callStatic("create")
php artisan migrate
SQLSTATE[42000]: Syntax error or access violation: 1072 Key column 'user_id' doesn't exist in table (SQL: alter table `blog_posts` add constraint `blog_posts_user_id_foreign` foreign key (`user_id`) references `users` (`id`))
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
+12 vendor frames
13 database/migrations/2022_01_08_112722_create_blog_posts_table.php:26
Illuminate\Support\Facades\Facade::__callStatic("create")
class UserTableSeeder extends Seeder
{
public function run()
{
$users = [
[
'name' => 'Author',
'email' => 'seriiburduja@mail.ru',
'password' => bcrypt('seriiserii;')
],
[
'name' => 'Admin',
'email' => 'seriiburduja@gmail.com',
'password' => bcrypt('seriiserii;')
]
];
DB::table('users')->insert($users);
}
}
Column 'user_id' cannot be null
- в миграции у этого поля нету свойства ->nullable(), поэтому и не должно быть null.
/home/serii/Videos/vue-course/09.m3u