问题
Im having trouble figuring out this migrations business for CodeIgniter ... I cant find any decent documentation that explains additional field elements like current_timestamp, default datetime values etc etc
I was wondering if someone could help me out to translate the following into proper dbforge->add_field arrays
I need the following 2
`last_login` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
and
`created` datetime NOT NULL DEFAULT '0000-00-00 00:00:00'
I have copied these from the SQL insert statement from the tank_auth library.
But i want to put it into migrations now.
Cheers,
回答1:
for number 1 you can use
$this->dbforge->add_field('last_login TIMESTAMP');
or
$data = array(
'type' => 'TIMESTAMP'
);
This auto inserts ON UPDATE CURRENT_TIMESTAMP
回答2:
I think you may be out of luck. These are the available options to dbforge:
Additionally, the following key/values can be used:
unsigned/true : to generate "UNSIGNED" in the field definition. default/value : to generate a default value in the field definition. null/true : to generate "NULL" in the field definition. Without this, the field will > default to "NOT NULL". auto_increment/true : generates an auto_increment flag on the field. Note that the > field type must be a type that supports this, such as integer
You may have to pass a standard query. $this->db->query('YOUR QUERY HERE'); may be what you need.
来源:https://stackoverflow.com/questions/12685986/codeigniter-additional-dbforge-migration-fields