simolus3 / drift

Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
https://drift.simonbinder.eu/
MIT License
2.39k stars 343 forks source link

[drift_postgres] Cannot insert null value to default column #2981

Closed davidmartos96 closed 2 weeks ago

davidmartos96 commented 2 weeks ago

I'm running into an issue when using the drift_postgres package that doesn't occurr when using the postgres package.

For the following table:

CREATE TABLE IF NOT EXISTS public.parent (
  id INTEGER PRIMARY KEY NOT NULL,
  value TEXT,
  other INTEGER DEFAULT 0
);

This works using postgres:

    await db.execute('''
INSERT INTO public.parent (id, value, other) VALUES (3, 'hi', \$1);
''',
      parameters: [null],
    );

This doesn't work using drift

await db.customInsert('''
INSERT INTO public.parent (id, value, other) VALUES (3, 'hi', \$1);
''', variables: [Variable(null)]);

The error is Severity.error 42804: column "other" is of type integer but expression is of type text hint: You will need to rewrite or cast the expression.

simolus3 commented 2 weeks ago

Thanks for the help finding and fixing this, I've released version 1.2.2.