zofe / rapyd-laravel

deprecated rewritten in rapyd-livewire
MIT License
866 stars 297 forks source link

Integrity constraints when inserting record #246

Open kmligue opened 9 years ago

kmligue commented 9 years ago

I have this migration

Schema::create('contacts', function(Blueprint $table) {
            // InnoDB so we can enforce referential integrity
            $table->engine = 'InnoDB';

            // Columns
            $table->string('first_name');
            $table->string('last_name');

            // Standard
            $table->timestamps();
            $table->softDeletes();
        });

First name is required. Everytime i do insertion in that table it will display an error

Integrity constraint violation: 1048 Column 'last_name' cannot be null(SQL: insert into `contacts` (`first_name`, `last_name`) values (Tracy, 2015-11-10 03:20:14, 2015-11-10 03:20:14))

Should the query have '' on empty field?

zofe commented 9 years ago

you should also paste some dataform/dataedit code about the insertion and some relevant part of model (if you used a model)

tacone commented 9 years ago

That query is very wrong, not sure if it eloquent or the logger to be wrong.

A workaround would be to set the fields as ->nullable().

kmligue commented 9 years ago

This is my DataForm:

$create = \DataForm::source(new Contacts);
$create->link("contacts","Contacts", "TR")->back();
$create->add('first_name','First Name', 'text')->rule('required');
$create->add('last_name','Last Name','text');
$create->submit('save');

return $create->view('contacts.create', compact('create'));

I've tried DataEdit also but the error is still the same.

zofe commented 9 years ago

last name should be nullable as @tacone said or you must add a required rule for last_name too.