Project

General

Profile

Actions

Bug #76508

closed

Comparison of NOT NULL fields without a default value does not work in "Compare Database" tool if a field is not autoincrement

Added by M. Stichweh almost 8 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Install Tool
Target version:
-
Start date:
2016-06-07
Due date:
% Done:

100%

Estimated time:
1.00 h
TYPO3 Version:
7
PHP Version:
5.6
Tags:
Complexity:
easy
Is Regression:
No
Sprint Focus:

Description

In some cases you would like to have a field which should never be NULL, eg. a referencing ID to parent object. But if a database field is defined as NOT NULL field without a default value the comparison does not work because the tool expects NULL as default value. A default of '0' would work but allows inserting of rows without the specific field explicit set.

For example the SQL definition looks like that:

CREATE TABLE tx_foo (
    uid int(11) unsigned NOT NULL auto_increment,
    pid int(11) unsigned DEFAULT '0' NOT NULL,
    tstamp int(11) unsigned DEFAULT '0' NOT NULL,
    crdate int(11) unsigned DEFAULT '0' NOT NULL,

    someid int(11) unsigned NOT NULL,

    PRIMARY KEY (uid),
    KEY parent (pid),
    KEY someid (someid)
) ENGINE=InnoDB;

The install tool will always show a difference for the "someid" field and expects:

someid int(11) unsigned DEFAULT NULL NOT NULL,

But this would result in invalid SQL when creating the table.
So the SqlSchemaMigrationService should be modified to prevent this edge case:

LINE 517 in SqlSchemaMigrationService.php (assembleFieldDefinition method)

    // Add a default value if the field is not auto-incremented (these fields never have a default definition)
    // but not if the field can not be NULL and default value is NULL (this results in invalid SQL)
    if (!stristr($row['Extra'], 'auto_increment') && !($row['Null'] == 'NO' && $row['Default'] === NULL)) {


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Bug #76641: Database compare and "NULL default NULL" is not recognizedClosed2016-06-15

Actions
Related to TYPO3 Core - Feature #77643: Reimplement SqlSchemaMigrationService using SchemaManagerClosedMorton Jonuschat2016-08-25

Actions
Actions

Also available in: Atom PDF