ducaale / university-management-app

a little project for my second semester in college
0 stars 0 forks source link

php artisan db:seed problem #2

Closed odyright closed 8 years ago

odyright commented 8 years ago

[Illuminate\Database\QueryException] SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (testapp.batches, CONSTRAINTbatches_department_id_foreignFOREIGN KEY (department_id) REFERENCES
departments(id)) (SQL: insert intobatches(batch_name,department_id,updated_at,created_at) valu es (BE6, 1, 2016-02-27 18:28:23, 2016-02-27 18:28:23))

[PDOException] SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (testapp.batches, CONSTRAINTbatches_department_id_foreignFOREIGN KEY (department_id) REFERENCES
departments(id))

How to solve it?

ducaale commented 8 years ago

thanks for your interest now I have updated the seed files try it in this order

php artisan db:seed -class=facultyTableSeeder
php artisan db:seed -class=departmentTableSeeder
php artisan db:seed -class=batchesTableSeeder
php artisan db:seed -class=genderTableSeeder
php artisan db:seed -class=userTableSeeder
php artisan db:seed -class=guardiansTableSeeder
php artisan db:seed -class=studentsTableSeeder

PS: this is app is a work in progress

odyright commented 8 years ago

ok i see but modify the -class to --class and i think you forgot that the student and the guardians doesn't exist in seeds folder.

ducaale commented 8 years ago

ok now fixed it. by the way I added the student and guardians seeder files earlier

odyright commented 8 years ago

yeah, good but in seeds folder the DatabaseSeeder.php is missing... without it the migration couldn't be reached successfully.

odyright commented 8 years ago

here you are:

<?php

use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();

        $this->call(batchesTableSeeder::class);
        $this->call(studentsTableSeeder::class);
        $this->call(guardiansTableSeeder::class);
        $this->call(departementTableSeeder::class);
        $this->call(facultyTableSeeder::class);
        $this->call(genderTableSeeder::class);
        $this->call(userTableSeeder::class);

        Model::reguard();
    }
}
ducaale commented 8 years ago

thanks! now I have added the database seeder file

odyright commented 8 years ago

the php artisan db:seed generated sql error. So i think it would be better to do it individually as you mentionned above.

ducaale commented 8 years ago

the error is due to order of seeding the database. now I have modified the seeder file hopefully it will work now

odyright commented 8 years ago

problem with the departmentTableSeeder file

ducaale commented 8 years ago

run php artisan migrate:refresh then use the last seeder files i uploaded php artisan db:seed