dimanche 29 septembre 2019

Laravel 5.5.* SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed

I am trying to add a new user to my database using the RegistrationController provided by Laravel. Every time I try to register a new user it hits me with an error saying a not null constraint has failed, even though I am not submitting any null fields. At first I thought it was a problem specifically with the address field until I made it nullable in my migration to get around the error, and the not null constraint on the next field also failed. I have double checked all my migration files, and even dumped the data I'm trying to pass into the database to double check nothing is null. The error message tells me it's not even trying to pass the information I've provided to the database, but I have no idea how to fix this problem.

My migration:

    Schema::create('users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('email')->unique();
            $table->string('password');
            $table->string('address');
            $table->string('user_type');
            $table->boolean('approved')->nullable();
            $table->rememberToken();
            $table->timestamps();
        });

My create function in the Register Controller:

    protected function create(array $data)
    {
        return User::create([
            'address' => $data['address'],
            'name' => $data['name'],
            'email' => $data['email'],
            'user_type' => $data['user_type'],
            'password' => Hash::make($data['password'])
        ]);
    }

The result of my data dump:

       array:7 [▼
  "_token" => "d5qCwoIqyfiF1q5FyAIhi3gHEm5CA7OHpDZVRKSI"
  "name" => "test"
  "email" => "asasdfasd@sdfgsdfgg.com"
  "address" => "1637 test street"
  "user_type" => "Customer"
  "password" => "12345678"
  "password_confirmation" => "12345678"
]

And the error I'm getting:

SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: 
users.address (SQL: insert into "users" ("name", "email", "password", "updated_at", "created_at") 
values (test, asasdfasd@sdfgsdfgg.com, $2y$10$q1Kc0A80cd0ARJbvTtpiee59fJ8g4orilFWjNV5igihPDWQeoYhjG, 2019-09-29 08:57:58, 2019-09-29 08:57:58))

Any help anyone could provide me would be greatly appreciated. If you need any more snippets of my code please let me know. Thanks in advanced.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2nzD14m
via IFTTT

Aucun commentaire:

Enregistrer un commentaire