dimanche 24 mai 2020

Generated database field with migrations

I have two float fields: fieldA and fieldB. I would like to store in DB float field fieldC, which will always have value: fieldA * fieldB.

I would like to achieve that with migrations. This is what I tried

$table->float('fieldC', 12, 2)->storedAs('fieldA * fieldB');

and

$table->float('fieldC', 12, 2)->storedAs('MULTIPLY(fieldA, fieldB)');

Both didn't work. Errors are Column not found: 1054 Unknown column 'fieldA' and General error: 1901 Function or expression 'MULTIPLY()' cannot be used.

Any suggestions?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire