Feature #91688
closedTCA: Make default value mandatory for some field types if SQL field defined as "NOT NULL" - avoid error in extensions due to strict and missing default
0%
Description
I propose to generate a warning if TCA does not have a default value and the field is defined as "NOT NULL" in ext_tables.sql
For some fields, this may not be necessary (e.g. select, passthrough).
Fields where it could be checked: e.g. input.
To be honest, I have not entirely figured out when it is a problem and will create an error and when a default is set automatically.
See also Stack Overflow questions:
- TYPO3: SQL error: 'Incorrect integer value: '' for column 'sys_language_uid' at row 1'
- How to set default values correctly in TCA to avoid strict error messages and when is it necessary? (without answer)
An alternative solution might be that the TCA default value is automatically set correctly due to the type of the DB field.
Newer Versions of MySQL / MariaDB have strict (STRICT_TRANS_TABLES) by default.
If you have the SQL field defined as NOT NULL and no default is set via TCA, you might get an error like this:
SQL error: Field `something` doesn't have a default value
I had this problem with ods_osm (which has now been patched, so it is not resproducible anymore).
Reproduce¶
- Set your database to strict, e.g. sql_mode=STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION, ...
- Use extension ods_osm
- Remove the default line in TCA overrides for fe_groups https://github.com/bobosch/ods_osm/blob/master/Configuration/TCA/Overrides/fe_groups.php
- Clear cache
- Create a new FE group
You should now see the above error
The problem with missing defaults is only a problem with extensions as the core does not have the problem because it sets the defaults correctly. However, I think this setting might prevent problems in the future where extension authors test with a database server without strict setting and may not be aware of the problem their extension might be causing.
With other systems, it is enough to define the table schema with a default value. With TYPO3 it is not enough.
Updated by Rémy DANIEL almost 4 years ago
- Related to Bug #88331: MySQL strict mode: let integer time fields be filled with NULL added
Updated by Sybille Peters 5 months ago
- Status changed from New to Closed
Closing due to:
- no watchers
- no comments
- no Status "Accepted"
- open since 2020
There were some problems when DB server started using "strict" by default but these could all be solved by modifying the TCA in extensions. Since then, the problem is no longer as relevant and perhaps not necessary to add additional checks in the core.