Feature(s) impacted
- forest-cli schema:update
- Forest Admin (WebUI)
- Manipulating table content via (at least INSERT)
Observed behavior
When generating the model for a table with a field like the following:
+----------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+--------------+------+-----+---------+----------------+
| email | varchar(64) | YES | | | |
+----------------+--------------+------+-----+---------+----------------+
It sets the entries as follows:
email: {
type: DataTypes.STRING,
defaultValue: Sequelize.literal(''),
},
However when I now want to do an INSERT (alias create) operation on the table without handing in a value for “email” it fails due to an invalid syntax.
This also happens via the Forestadmin WebUI too when duplicating an entry and keeping that field empty (this was triggering my analysis). I can see in the logs that the value is actually missing, see the missing “?” at the end behind the “,”:
INSERT INTO `users` (`id`,`username`,`hash`,`name`,`token`,`role`,`email`) VALUES (DEFAULT,?,?,?,?,?,);
I would actually expect another DEFAULT there (which works with a manual SQL INSERT) but I’m no expert in the field.
When I exchange “Sequelize.literal(‘’)” with null or simply an empty string “” it works well.
Expected behavior
forest-cli should create a model with which it’s possible to create a new entry without changes to the models.
Failure Logs
Trace: ERROR: SequelizeDatabaseError: (conn=56, no: 1064, SQLState: 42000) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ')' at line 1
Context
- Project name: Bocoloco
- Team name: Operations
- Environment name: Production and Staging
- Agent (forest package) name & version: forest-express-sequelize 9.3.5
- Database type:
- MariaDB 10.3 with mysql connector 2.3.0
- MariaDB 11 with mariadb connector 2.5.6)
- Recent changes made on your end if any: There should be no related changes