Skip to content

Seeding fails #52

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
fbraem opened this issue Oct 13, 2013 · 8 comments
Closed

Seeding fails #52

fbraem opened this issue Oct 13, 2013 · 8 comments

Comments

@fbraem
Copy link

fbraem commented Oct 13, 2013

When I try to seed the MongoDB I get the following error:

[ErrorException]
Argument 2 passed to Illuminate\Database\Query\Builder::__construct() must
be an instance of Illuminate\Database\Query\Grammars\Grammar, null given, c
alled in /home/bronx/www/zumuta/laravel/vendor/laravel/framework/src/Illumi
nate/Database/Eloquent/Model.php on line 1514 and defined

@jenssegers
Copy link
Contributor

Are you using the correct connection?

@fbraem
Copy link
Author

fbraem commented Oct 15, 2013

I think so ... The user model (reused from Laravel) is correctly seeded. My own model fails ...

This is my DatabaseSeeder class:

<?php

class DatabaseSeeder extends Seeder {

    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Eloquent::unguard();

        $this->call('UserTableSeeder');
        $this->call('ArticleTableSeeder');
        $this->call('PageTableSeeder');
    }
}

And this is the ArticleTableSeeder:

<?php

class ArticleTableSeeder extends Seeder {

    public function run()
    {
        echo "Seeding Articles ...";
        DB::table('articles')->delete();

        $user = User::where('username', 'root')->first();

        if ( $user )
        {
            Article::create(array(
            'title'   => 'First post',
            'slug'    => 'first-post',
            'body'    => 'Lorem ipsum',
            'user_id' =>  $user->getKey()
            )); 
        }

        echo "Seeded.";
    }
}

And this is the Article model:

<?php
use Jenssegers\Mongodb\Model as Eloquent;

class Article extends \Eloquent {

    protected $collection = 'articles';

    protected static $unguarded = true;

    public function author()
    {
        return $this->belongsTo('User');
    }

}

@jenssegers
Copy link
Contributor

Seeding works for me.

jenssegers added a commit that referenced this issue Oct 19, 2013
@fbraem
Copy link
Author

fbraem commented Oct 19, 2013

Problem solved: my Article model extended from \Eloquent. When removing the backslash I can seed using the Article model.

Thanks for your time.

@fbraem fbraem closed this as completed Oct 19, 2013
@ganapathi-threesquare
Copy link

hi Even i am facing the same problem can u tell where i need change which file???

mac:FASE kakashi$ php artisan authentication:install
Migrated: 2014_02_19_095545_create_users_table
Migrated: 2014_02_19_095623_create_user_groups_table
Migrated: 2014_02_19_095637_create_groups_table
Migrated: 2014_02_19_095645_create_user_throttle_table
Migrated: 2014_02_19_160516_create_permission_table
Migrated: 2014_02_26_165011_create_user_profile_table
Migrated: 2014_05_06_122145_create_profile_field_types
Migrated: 2014_05_06_122155_create_profile_field

[ErrorException]
Argument 2 passed to Illuminate\Database\Query\Builder::__construct() must
be an instance of Illuminate\Database\Query\Grammars\Grammar, null given, c
alled in /Applications/XAMPP/xamppfiles/htdocs/FASE/vendor/laravel/framewor
k/src/Illuminate/Database/Eloquent/Model.php on line 1787 and defined

@ganapathi-threesquare
Copy link

hi i am waiting for the response........

@fbraem
Copy link
Author

fbraem commented Aug 12, 2014

Are you always so impatient? Read my answer on how I solved it. It's probably something in your code ...

@jenssegers
Copy link
Contributor

I added a troubleshooting section to the readme that explains this error: https://github.com/jenssegers/laravel-mongodb#troubleshooting

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants