Comments (9)
Can you add a real example? please.
from migrations.
Please see generated and edited files of the migration.
from migrations.
Generated file:
<?php
class WrongAlterTable extends CakeMigration {
/**
* Migration description
*
* @var string
* @access public
*/
public $description = '';
/**
* Actions to be performed
*
* @var array $migration
* @access public
*/
public $migration = array(
'up' => array(
'create_field' => array(
'calendar_event_types' => array(
'order' => array('type' => 'integer', 'null' => false, 'default' => '0', 'after' => 'id'),
'active' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'after' => 'order'),
),
'calendar_holidays' => array(
'indexes' => array(
'date' => array('column' => array('date', 'type'), 'unique' => 1),
),
),
),
'drop_field' => array(
'calendar_event_types' => array('name', 'created', 'modified',),
'calendar_holidays' => array('', 'indexes' => array('type', 'date')),
),
),
'down' => array(
'drop_field' => array(
'calendar_event_types' => array('order', 'active',),
'calendar_holidays' => array('', 'indexes' => array('date')),
),
'create_field' => array(
'calendar_event_types' => array(
'name' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 100, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL),
'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL),
),
'calendar_holidays' => array(
'indexes' => array(
'type' => array('column' => 'type', 'unique' => 0),
'date' => array(),
),
),
),
),
);
/**
* Before migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function before($direction) {
return true;
}
/**
* After migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function after($direction) {
return true;
}
}
Edited file:
<?php
class GoodAlterTable extends CakeMigration {
/**
* Migration description
*
* @var string
* @access public
*/
public $description = '';
/**
* Actions to be performed
*
* @var array $migration
* @access public
*/
public $migration = array(
'up' => array(
'drop_field' => array(
'calendar_event_types' => array('name', 'created', 'modified',),
'calendar_holidays' => array('indexes' => array('type', 'date')),
),
'create_field' => array(
'calendar_event_types' => array(
'order' => array('type' => 'integer', 'null' => false, 'default' => '0', 'after' => 'id'),
'active' => array('type' => 'boolean', 'null' => false, 'default' => '1', 'after' => 'order'),
),
'calendar_holidays' => array(
'indexes' => array(
'date' => array('column' => array('date', 'type'), 'unique' => 1),
),
),
),
),
'down' => array(
'drop_field' => array(
'calendar_event_types' => array('order', 'active',),
'calendar_holidays' => array('indexes' => array('date')),
),
'create_field' => array(
'calendar_event_types' => array(
'name' => array('type' => 'string', 'null' => false, 'default' => NULL, 'length' => 100, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
'created' => array('type' => 'datetime', 'null' => false, 'default' => NULL),
'modified' => array('type' => 'datetime', 'null' => false, 'default' => NULL),
),
'calendar_holidays' => array(
'indexes' => array(
'type' => array('column' => 'type', 'unique' => 0),
'date' => array('column' => 'date', 'unique' => 0),
),
),
),
),
);
/**
* Before migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function before($direction) {
return true;
}
/**
* After migration callback
*
* @param string $direction, up or down direction of migration process
* @return boolean Should process continue
* @access public
*/
public function after($direction) {
return true;
}
}
from migrations.
Ok 2 more questions:
- How did you generated that file? I mean, what command did you type
- Can you give me the sql dump with the structure of this table?
from migrations.
- Ubuntu: lib/Cake/Console/cake Migrations.migration generate
- Sql (after apply migration):
--
-- Table structure for table `calendar_event_types`
--
DROP TABLE IF EXISTS `calendar_event_types`;
CREATE TABLE IF NOT EXISTS `calendar_event_types` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`order` int(11) NOT NULL DEFAULT '0',
`active` tinyint(1) NOT NULL DEFAULT '1'
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
-- --------------------------------------------------------
--
-- Table structure for table `calendar_holidays`
--
DROP TABLE IF EXISTS `calendar_holidays`;
CREATE TABLE IF NOT EXISTS `calendar_holidays` (
`id` char(36) NOT NULL,
`date` date NOT NULL,
`type` int(11) NOT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `date` (`date`,`type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Store days';
from migrations.
I'm sorry, I meant the sql structe before running migrations.
And I have these comments:
In your sql structure, there's a missing ", " in "calendar_event_types" after defining "active" field.
I want to see the sql structure before running this migration file because you have a drop field instruction in "calendar_event_types" with a field that does not exist (name)
from migrations.
Sorry, I cannot prepare sql right now, you can get it run right migration down. Please try. If not, tell me, I'll do it when I will on my computer.
from migrations.
No, I couldn't. I am interested in reproducing the exact scenario you are describing, that's why I would like to get the sql structure before you generated the migration file. Thanks!
from migrations.
Closing issue since I wasn't able to reproduce the bug and the reporter didn't give the information needed
from migrations.
Related Issues (20)
- Error "Cannot use 'String' as class name as it is reserved" HOT 1
- MySQL constraint HOT 2
- Table name with space leads to invalid migration script HOT 2
- Question: why does the doc says one need to drop a field when altering its indexes? HOT 1
- Shell command to jump to certain migration version HOT 1
- Class 'Object' not found HOT 1
- New compare option is not documented HOT 1
- Add numeric type to support the precision.
- always all migrations are applied
- Change of string column length to 255 detected but not executed HOT 5
- Invalid translation HOT 2
- Compare database to schema.php not documented HOT 1
- Migration Generation Automation HOT 3
- Migration error with mongo HOT 3
- Can not create table schema_migrations when Init plugin HOT 5
- generateModel() creates model instances but cake loads associated models automatically HOT 1
- Notice Error: Undefined index: column leading to invalid SQL HOT 1
- Changing the table comment rebuilds the table on MySQL
- It's possible to use migrations for custom plugin? HOT 6
- Create field after/before another HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from migrations.