From: Jaime Soriano Pastor Date: Wed, 21 Dec 2011 12:05:02 +0000 (+0100) Subject: Avoid the posibility of having 'NOT NULL DEFAULT NULL' with primary keys in MySQL... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=5fc21d2ee9cd2ea10d5ad04a151c66259e3fee23;p=dbsrgits%2FSQL-Translator.git Avoid the posibility of having 'NOT NULL DEFAULT NULL' with primary keys in MySQL producer --- diff --git a/lib/SQL/Translator/Producer/MySQL.pm b/lib/SQL/Translator/Producer/MySQL.pm index bd53796..7fab1ac 100644 --- a/lib/SQL/Translator/Producer/MySQL.pm +++ b/lib/SQL/Translator/Producer/MySQL.pm @@ -612,7 +612,9 @@ sub create_field } # Null? - $field_def .= ' NOT NULL' unless $field->is_nullable; + if (not ($field->is_nullable || $field->is_primary_key)) { + $field_def .= ' NOT NULL'; + } # Default? SQL::Translator::Producer->_apply_default_value( diff --git a/t/30sqlt-new-diff-mysql.t b/t/30sqlt-new-diff-mysql.t index 3bd1653..0a00151 100644 --- a/t/30sqlt-new-diff-mysql.t +++ b/t/30sqlt-new-diff-mysql.t @@ -74,7 +74,7 @@ ALTER TABLE new_name ADD COLUMN new_field integer; ALTER TABLE person ADD COLUMN is_rock_star tinyint(4) DEFAULT 1; -ALTER TABLE person CHANGE COLUMN person_id person_id integer(11) NOT NULL auto_increment; +ALTER TABLE person CHANGE COLUMN person_id person_id integer(11) auto_increment; ALTER TABLE person CHANGE COLUMN name name varchar(20) NOT NULL; @@ -129,7 +129,7 @@ ALTER TABLE old_name RENAME TO new_name, ALTER TABLE person DROP INDEX UC_age_name, ADD COLUMN is_rock_star tinyint(4) DEFAULT 1, - CHANGE COLUMN person_id person_id integer(11) NOT NULL auto_increment, + CHANGE COLUMN person_id person_id integer(11) auto_increment, CHANGE COLUMN name name varchar(20) NOT NULL, CHANGE COLUMN age age integer(11) DEFAULT 18, CHANGE COLUMN iq iq integer(11) DEFAULT 0, @@ -199,7 +199,7 @@ ALTER TABLE employee DROP FOREIGN KEY FK5302D47D93FE702E, ALTER TABLE person DROP INDEX UC_age_name, DROP INDEX u_name, ADD COLUMN is_rock_star tinyint(4) DEFAULT 1, - CHANGE COLUMN person_id person_id integer(11) NOT NULL auto_increment, + CHANGE COLUMN person_id person_id integer(11) auto_increment, CHANGE COLUMN name name varchar(20) NOT NULL, CHANGE COLUMN age age integer(11) DEFAULT 18, CHANGE COLUMN iq iq integer(11) DEFAULT 0, diff --git a/t/64xml-to-mysql.t b/t/64xml-to-mysql.t index fea07b0..2beb6d0 100644 --- a/t/64xml-to-mysql.t +++ b/t/64xml-to-mysql.t @@ -35,7 +35,7 @@ my @want = ( q[DROP TABLE IF EXISTS `Basic`], q[CREATE TABLE `Basic` ( - `id` integer(10) zerofill NOT NULL auto_increment, + `id` integer(10) zerofill auto_increment, `title` varchar(100) NOT NULL DEFAULT 'hello', `description` text DEFAULT '', `email` varchar(500), @@ -54,7 +54,7 @@ my @want = ( q[DROP TABLE IF EXISTS `Another`], q[CREATE TABLE `Another` ( - `id` integer(10) NOT NULL auto_increment, + `id` integer(10) auto_increment, `num` numeric(10, 2), PRIMARY KEY (`id`) ) ENGINE=InnoDB],