statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
104 stars 74 forks source link

Change ID type on form_submissions to be a float #287

Closed ryanmitchell closed 4 months ago

ryanmitchell commented 4 months ago

This PR updates the id type on form_submissions to be a float, rather than an int, so that out of the box it works on Postgres.

@andreas-eisenmann would you mind checking that this migration works in your situation?

Closes https://github.com/statamic/eloquent-driver/issues/286

andreas-eisenmann commented 4 months ago

@ryanmitchell thanks! First try after executing the migration fails with:

SQLSTATE[23502]: Not null violation: 7 ERROR: null value in column "id" of relation "form_submissions" violates not-null constraint DETAIL: Failing row contains (null, {"date": "2024-05-15T11:42:30.516004Z", "email": "andreas.eisenm..., 2024-05-15 13:42:30.516004, 2024-05-15 13:42:30.519891, 1)

I will start debuging now to find the root cause for this error.

andreas-eisenmann commented 4 months ago

Now with your changes in https://github.com/statamic/eloquent-driver/commit/9a37ad8cef71eac4b6c851dc621fe3cafd7474a8 it works. 👍️

lazerg commented 3 months ago

Hi @ryanmitchell,

After updating, this code stopped to work.

I migrated new migration but anyway it is not working?

image

Error:

local.ERROR: SQLSTATE[HY000]: General error: 1364 Field 'id' doesn't have a default value (Connection: mysql, SQL: insert into `statamic_form_submissions` (`form`, `data`, `updated_at`, `created_at`) values (success-stories, {"email":"lazerg2@gmail.com","companyName":"myCompany","firstName":"Lazizbek","date":"2024-06-27T01:49:07.017736Z"}, 2024-06-27 11:49:07.018737, 2024-06-27 11:49:07.018737))
ryanmitchell commented 3 months ago

@lazerg if you are make()-ing the model directly you'll need to specify an id, it no longer auto increments.

Instead you should make on the Facade:


\Statamic\Facades\Form::find('success-stores')->makeSubmission()
    ->data([...])->save();