I set up a quick and dirty migration to add two columns to two tables. These are to be basically boolean 1/0 switch fields. I'm setting up my migration file as follows, note the 'not null' in both column types:
<?php
namespace Craft;
class m171020_153541_grnplatform_AutoRenewUpdate extends BaseMigration
{
public function safeUp()
{
$this->addColumn('grnplatform_payment_cards', 'expireNotified', "tinyint(1) unsigned NOT NULL DEFAULT '0'");
$this->addColumn('grnplatform_subscriptions', 'failedRenew', "tinyint(1) unsigned NOT NULL DEFAULT '0'");
return true;
}
public function safeDown() {
$this->dropColumn('grnplatform_payment_cards', 'expireNotified');
$this->dropColumn('grnplatform_subscriptions', 'failedRenew');
return true;
}
}
However after the migration runs, my show create table
command yields this:
CREATE TABLE `craft_grnplatform_subscriptions` (
`id` int(11) NOT NULL,
`userId` int(11) NOT NULL,
`active` tinyint(1) unsigned NOT NULL DEFAULT '1',
`renewalPeriod` enum('monthly','quarterly','yearly') COLLATE utf8_unicode_ci DEFAULT NULL,
`autoRenew` tinyint(1) unsigned NOT NULL DEFAULT '0',
`lastRenewal` date NOT NULL,
`nextRenewal` date NOT NULL,
`failedRenew` tinyint(1) unsigned DEFAULT '0',
`dateCreated` datetime NOT NULL,
`dateUpdated` datetime NOT NULL,
`uid` char(36) COLLATE utf8_unicode_ci NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `craft_grnplatform_subscriptions_userId_unq_idx` (`userId`),
KEY `craft_grnplatform_subscriptions_nextRenewal_idx` (`nextRenewal`),
CONSTRAINT `FK_craft_grnplatform_subscriptions_craft_grnplatform_vendor_data` FOREIGN KEY (`userId`) REFERENCES `craft_grnplatform_vendor_data` (`userId`) ON DELETE CASCADE,
CONSTRAINT `craft_grnplatform_subscriptions_id_fk` FOREIGN KEY (`id`) REFERENCES `craft_elements` (`id`) ON DELETE CASCADE,
CONSTRAINT `craft_grnplatform_subscriptions_userId_fk` FOREIGN KEY (`userId`) REFERENCES `craft_users` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
Notice how the "not null" is missing from the column declaration for 'failedRenew`...
How can get set the NOT NULL value on a column I'm adding from a migration?