After doing some testing I found out that with the User model when I have it extend Eloquent it works but if I have it extend BaseModel which extends Eloquent then it doesn't work. What is the reason for this?
Nov 12, 2014
55
Level 54
Seeding Issue
I'm trying to seed my database and it gets down to the NewsArticlesTableSeeder and it fails due to it not being able to place a value in for the poster_id as the error indicates however I'm trying to find out why this is.
Inside the NewsArticlesTableSeeder I dd() on the userIds and I keep getting an empty array and I don't know why that is if I'm getting that Seeded message saying it works on the Users table.
Me-iMac:manager me$ php artisan db:seed
Seeded: UserRolesTableSeeder
Seeded: UserStatusesTableSeeder
Seeded: UsersTableSeeder
Seeded: UserProfilesTableSeeder
Seeded: NewsCategoriesTableSeeder
[Illuminate\Database\QueryException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'poster_id' cannot be null (SQL: insert into `news_articles` (`poster_id`, `date_posted`, `title`, `content`, `news_category_id`, `visible`, `updated_at`, `created_at`) values (, 2014-11-17 20:12:54, Ut illo omnis sed natus minima., Quis aliquam dolorem q
uaerat tenetur animi sequi. Dolorem ab molestiae sed non iusto consequuntur dolores adipisci. Nulla eum sequi recusandae atque tenetur cupiditate quo. Iste deserunt eius alias dolor et omnis.
Sed laborum rerum eaque aut. Ipsa laboriosam ipsam eveniet qui odit. Dignissimos non ea aut quasi. Et modi in quis.
Voluptatibus dignissimos enim minus temporibus sed vero rerum eos. Et numquam suscipit sapiente debitis. Ipsa totam necessitatibus beatae aut illum impedit.
Modi dolor nam quia eos. Qui esse maiores voluptas sint. In ratione soluta sed incidunt. Temporibus labore et facilis animi autem. Voluptas ipsa minus animi quidem.
Velit nihil ut et id molestias eaque. Quo esse et nihil labore aspernatur. Commodi eius dicta velit soluta voluptas.
Accusantium dolores omnis repellat minima. Voluptas recusandae eveniet quibusdam expedita ipsa. Dolor perspiciatis qui nihil voluptatem nam eaque rerum.
Facere vero illum quas. Totam consequatur voluptatem quam nihil qui., 7, yes, 2014-11-12 22:20:02, 2014-11-12 22:20:02))
[PDOException]
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'poster_id' cannot be null
db:seed [--class[="..."]] [--database[="..."]] [--force]
<?php
// Composer: "fzaninotto/faker": "v1.3.0"
use Faker\Factory as Faker;
class NewsArticlesTableSeeder extends Seeder {
public function run()
{
$faker = Faker::create();
$userIds = User::lists('id');
dd($userIds);
$categoryIds = NewsCategory::lists('id');
foreach(range(1, 10) as $index)
{
NewsArticle::create([
'poster_id' => $faker->randomElement($userIds),
'date_posted' => $faker->dateTimeBetween('now', '+7 days'),
'title' => $faker->text(50),
'content' => $faker->text(1000),
'news_category_id' => $faker->randomElement($categoryIds),
'visible' => $faker->randomElement(array('yes', 'no')),
]);
}
}
}
Please or to participate in this conversation.