kirkbushell / eloquence

A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.
MIT License
537 stars 58 forks source link

Integrity constraint violation with UUID #27

Closed Zyles closed 8 years ago

Zyles commented 8 years ago

Another issue here...

Added use UUIDModel; and public $incrementing = false; to my User model.

I build the schema in migration with $table->char('id', $length = 36)->index(); instead of increments('id')

(Btw I think you should use binary(16) for performance http://iops.io/blog/storing-billions-uuid-fields-mysql-innodb/)

This seem to work so far. Now I want to seed my database and I get:

[PDOException]                                                               
  SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint fai  
  led: users.id

Seed looks like this:

        User::insert(
                [
                    'email'             => 'admin@example.com',
                    'app_id'            => 1,
                    'department_id'     => 0,
                    'firstname'         => 'Super',
                    'lastname'          => 'Admin',
                    'username'          => 'admin',
                    'active'            => 1,
                    'blocked'           => 0,
                    'password'          => Hash::make('admin')
                ]
        );

Thanks.

Zyles commented 8 years ago

Changed my seeding to:

$user = new User;

        $user->email            = 'admin@example.com';
        $user->app_id           = 1;
        $user->department_id    = 0;
        $user->firstname        = 'Super';
        $user->lastname         = 'Admin';
        $user->username         = 'admin';
        $user->active           = 1;
        $user->blocked          = 0;
        $user->password         = Hash::make('admin');

        $user->save();

Works now!

kirkbushell commented 8 years ago

Glad you were able to sort it out - and thanks for the suggestion about binary, really good idea :)