Adem
Adem

Reputation: 55

Add new fields to table with migration on codeigniter?

When I add new fields to table with migration on codeigniter, all records deleted on table. How can i keep old recors on my table with migration? Thank you.

Upvotes: 2

Views: 8745

Answers (2)

Jerry
Jerry

Reputation: 3586

Use add_column rather than add_field. add_field is used to define fields for table creation, add_column modifies an existing table. The docs are pretty confusing on that point.

Upvotes: 5

Mahidul Islam
Mahidul Islam

Reputation: 626

Its working for me. You can try this -

$this->load->database();    
$this->db->query("ALTER TABLE table_name ADD column_name TEXT NULL");

Upvotes: 0

Related Questions