When attempting to add a not null field with no default value but specifying an initial value the following error is encountered.
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0='ip', 1='0.0.0.0'' at line 1: UPDATE {node_revision} SET 0=:db_update_placeholder_0, 1=:db_update_placeholder_1; Array
(
[:db_update_placeholder_0] => ip
[:db_update_placeholder_1] => 0.0.0.0
)
in db_add_field() (line 2719 of includes/database/database.inc).
Field definition items:
$schema['node_revision']['fields']['ip'] = array(
'description' => 'The IP address from which the revision was made',
'type' => 'varchar',
'length' => 23, // allow for IPv6 addresses
'not null' => TRUE,
'initial' => '0.0.0.0',
);
add field call: db_add_field('node_revision', 'ip', $schema['node_revision']['fields']['ip']);
I believe this is due to line 340 of includes/database/mysql/schema.inc being this
->fields(array($field, $spec['initial']))
instead of
->fields(array($field => $spec['initial']))
I'll submit a patch momentarily.
Comment | File | Size | Author |
---|---|---|---|
#4 | 973314-schema-api-tests.patch | 6.98 KB | Damien Tournoud |
#1 | db_add_field_initial_value-973314-1.patch | 486 bytes | tekante |
Comments
Comment #1
tekante CreditAttribution: tekante commentedComment #2
Crell CreditAttribution: Crell commentedLooks right to me, but we'll let the testbot have a crack at it. Is there any chance of getting a unit test here, too?
Comment #3
haffmans CreditAttribution: haffmans commentedRan into the same problem in RC1. I need the functionality for a module I'm updating for D7.
The patch in #1 works for me and solves the problem.
Comment #4
Damien Tournoud CreditAttribution: Damien Tournoud commentedIntroducing full coverage of addition and removal of standard columns.
Comment #5
Crell CreditAttribution: Crell commentedPretty! Thanks, Damien. (I didn't review the unit tests line by line, but Damien's writing it and they clearly pass, so I'm OK with that.)
Comment #6
webchickA one line bug fix and 100+ lines of tests. Now that's a patch! :D
Committed to HEAD. Thanks!