Skip to content

Error 1048 dropping a NULL column and adding same named column back as NOT NULL in the same migration #384

@ikewalker

Description

@ikewalker

version 1.0.35

I discovered this issue when trying to execute a migration with gh-ost to drop a NULL column and add it back as NOT NULL with a default value in order to backfill the existing rows with a static value for that column.

Here is a simplified test to reproduce the issue:

-- Create test table
CREATE TABLE `test`.`foo` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `str` varchar(16) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

# Populate some data in the table to give gh-ost some rows to copy
mysqlslap --defaults-file=/Users/ikewalker/sandboxes/msb_5_6_35/my.sandbox.cnf \
  --iterations 100000 --create-schema=test --query="insert into foo (str) values (NULL);"

# Start loading more data into the table
# Leave this running when you start the migration so they are running concurrently
mysqlslap --defaults-file=/Users/ikewalker/sandboxes/msb_5_6_35/my.sandbox.cnf \
  --iterations 1000000 --create-schema=test --query="insert into foo (str) values (NULL);"

# Execute the migration to drop the str column and add it back as NOT NULL.
$ ./gh-ost --execute --allow-on-master --user msandbox --password msandbox \
  --port 5635 --switch-to-rbr --database test --table foo \
  --alter 'DROP str,ADD str varchar(16)  NOT NULL DEFAULT "bar"'

# gh-ost will start throwing the following error over and over again
2017-03-16 07:28:04 ERROR Error 1048: Column 'str' cannot be null; query=
			replace /* gh-ost `test`.`_foo_gho` */ into
				`test`.`_foo_gho`
					(`id`, `str`)
				values
					(?, ?)
		; args=[314115 <nil>]
Copy: 0/313964 0.0%; Applied: 0; Backlog: 100/100; Time: 21s(total), 21s(copy); streamer: mysql_sandbox5635-bin.000002:101884612; State: migrating; ETA: N/A```

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions