Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

DTech_Proz's avatar

SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "id" violates not-null constraint DETAIL: Failing row contains

Hi, Programmers

Please help me with this error I have been getting for some time now. I have deployed my app on Heroku everything works fine when I access the home page, but when I register a user I get the above error. Is there something wrong with my database tables?

public function up() {

    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->index();
        $table->string('usertype')->nullable();
0 likes
6 replies
Nakov's avatar

Nothing wrong in the database. Might be wrong in the way you are trying to create a user. Are you passing in a value for the id when you are trying to create a user?

DTech_Proz's avatar

Hi, thanks for your response

Here is my Register controller code :

protected function create(array $data)
{
    $settings = Settings::first();

    $user =  User::create([
        'name' => $data['name'],
        'email' => $data['email'],
        'usertype' => $data['usertype'],
        'password' => Hash::make($data['password']),
        'active'=>0,
        'token'=> Str::uuid(40),
        'bonus' => Carbon::now(),
        //'main_balance'=>$settings->signup_bonus,

    ]);
Nakov's avatar

@dtech_proz are you using a Postgres database? It seems like the data type of the id is invalid. You've got integer I've seen solutions to change the id to a serial datatype. But I am not sure how to solve that using Laravel directly.

You can update your Postgres maybe, or use a different db driver.

1 like
DTech_Proz's avatar

Thank you for your suggested solution, I think it will work if I use the MySQL database. I used the Postgres Database to test the APP.

Please or to participate in this conversation.