The reasons for this are explained in https://nubuilder.blogspot.com/2010/09/nubuilder-primary-keys.html
However, some of us may have to deal with pre-existing tables which use auto-incrementing integers (usually bigint) as PKs.
Happily nuBuilder will detect tables of this type (in most cases) and the correct PKs will be generated. This is achieved by the function
Code: Select all
db_is_auto_id($table, $primaryKey)
Code: Select all
return $row->Extra == 'auto_increment';
The work around, if the developer knows that all integer values used as primary keys are auto-increment, is to use the row type and look for 'int', i.e. if it is 'int' it is 'auto_increment'.
This gives a modified return expression of:
Code: Select all
return ($row->Extra == 'auto_increment' || str_contains($row->Type, 'int'));
If we wish to preserve full conformity with the legacy code, we can introduce a new global $nuConfig variable which we will call
$nuConfigIntegerPKsAuto , which would have a default value of false. The expression then becomes
Code: Select all
return ($row->Extra == 'auto_increment' || ($nuConfigIntegerPKsAuto && str_contains($row->Type, 'int')));
The modification of the function db_is_auto_id() along these lines would be most welcome.
No doubt there are other ways but this has been tested and it works.
Thanks
Neil