Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Database seeder throws error #8

Closed
rowild opened this issue Mar 19, 2019 · 7 comments
Closed

Database seeder throws error #8

rowild opened this issue Mar 19, 2019 · 7 comments

Comments

@rowild
Copy link
Contributor

rowild commented Mar 19, 2019

If I activate all seeds in dataabase/seeds/DatabaseSeeder using php artisan migrate:refresh --seed on an empty DB table, the following errors are thrown:

In Connection.php line 664:
                                                                                                                         
  SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'student_id' cannot be null (SQL: insert into `attendanc  
  es` (`present`, `student_id`, `section_id`, `updated_at`, `created_at`) values (2, , 19, 2019-03-19 13:42:18, 2019-03  
  -19 13:42:18))                                                                                                         
                                                                                                                         

In Connection.php line 458:
                                                                                            
  SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'student_id' cannot be null

If I run the same command on the same DB table again (meaning the DB has all the tables now), this errors are thrown:

In Connection.php line 664:
                                                                                                                         
  SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'department'; check that column/key exists (SQL: alter table `users` drop `department`)                                                                                  
                                                                                                                         

In Connection.php line 458:
                                                                                                                 
  SQLSTATE[42000]: Syntax error or access violation: 1091 Can't DROP 'department'; check that column/key exists

There was a departments (plural!) table. It gets remove somewhere at the beginning, when the artisan script starts. I guess that at the time, when the users table is called, the departments table does simply not exist anymore...

@rowild
Copy link
Contributor Author

rowild commented Mar 19, 2019

In case anybody else wants to use fake data for testing, activating all databse seeds won't work at the moment because of either student_id or teacher_id must not be NULL. This is the setup that helped me to get as much data as possible without any errors:

class DatabaseSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $this->call(SchoolsTableSeeder::class);
        $this->call(ClassesTableSeeder::class);
        $this->call(SectionsTableSeeder::class);
        $this->call(UsersTableSeeder::class);
        // $this->call(AttendancesTableSeeder::class);
        $this->call(SyllabusesTableSeeder::class);
        $this->call(NoticesTableSeeder::class);
        $this->call(EventsTableSeeder::class);
        $this->call(FeesTableSeeder::class);
        // $this->call(HomeworksTableSeeder::class);
        $this->call(RoutinesTableSeeder::class);
        // $this->call(NotificationsTableSeeder::class);
        $this->call(ExamsTableSeeder::class);
        $this->call(GradesystemsTableSeeder::class);
        // $this->call(CoursesTableSeeder::class);
        // $this->call(GradesTableSeeder::class);
        // $this->call(FeedbacksTableSeeder::class);
        $this->call(FormsTableSeeder::class);
        $this->call(BooksTableSeeder::class);
        $this->call(MessagesTableSeeder::class);
        $this->call(FaqsTableSeeder::class);
        $this->call(IssuedbooksTableSeeder::class);
        $this->call(AccountsTableSeeder::class);
        $this->call(AccountSectorsTableSeeder::class);
        // $this->call(StudentinfosTableSeeder::class);
        // $this->call(StudentboardexamsTableSeeder::class);
    }
}

@shone83
Copy link

shone83 commented Mar 19, 2019

In migrations in 2018_10_08_002853_add_department_class_teacher_to_users_table.php file instead of this:

        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['department']);
        });

do this:

        Schema::table('users', function (Blueprint $table) {
            $table->dropColumn(['department_id']);
        });

@changeweb
Copy link
Owner

@rowild I applied @shone83 's fix using a new pull request

@rowild
Copy link
Contributor Author

rowild commented Mar 19, 2019

Applied the fix manually, but when running the migrate:refresh 2x in a row, I get this error:

In Grammar.php line 36:
                              
  Array to string conversion 

I can't find any Grammar.php file...

@rowild
Copy link
Contributor Author

rowild commented Mar 19, 2019

This fix does not work. Please test with all seeds and run migrate:refresh at least twice and you'll see that there are still troubles.

@changeweb
Copy link
Owner

@rowild I forgot to uncomment a factory line from user seeder class after a certain test case. Now all my Seedings are working. Please take a look. Now I've updated the it via pull request.

mig-fix

@rowild
Copy link
Contributor Author

rowild commented Mar 20, 2019

This issue is solved, so I close it. Thank you, @changeweg.

@rowild rowild closed this as completed Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants