user_guide_src/source/installation/upgrade_migrations.rst
Upgrade Migrations ##################
.. contents:: :local: :depth: 2
Database Migrations Documentation CodeIgniter 3.x <http://codeigniter.com/userguide3/libraries/migration.html>_Database Migrations Documentation CodeIgniter 4.x </dbmgmt/migration>001_create_users, 002_create_posts) of migrations is not longer supported. Version 4 of CodeIgniter only supports the timestamp scheme (20121031100537_create_users, 20121031500638_create_posts) . If you have used sequential naming you have to rename each migration file... code-block:: console
php spark migrate
If your v3 project uses sequential migration names you have to change those to timestamp names.
You have to move all migration files to the new folder app/Database/Migrations.
Remove the line defined('BASEPATH') OR exit('No direct script access allowed'); if it exists.
Add this line just after the opening php tag: namespace App\Database\Migrations;.
Below the namespace App\Database\Migrations; line add this line: use CodeIgniter\Database\Migration;
Replace extends CI_Migration with extends Migration.
The method names within the Forge class has been changed to use camelCase. For example:
$this->dbforge->add_field to $this->forge->addField$this->dbforge->add_key to $this->forge->addKey$this->dbforge->create_table to $this->forge->addTable$this->dbforge->drop_table to $this->forge->addTable(optional) You can change the array syntax from array(...) to [...]
Upgrade the migration table, if you use the same database.
Path: application/migrations:
.. literalinclude:: upgrade_migrations/ci3sample/001.php
Path: app/Database/Migrations:
.. literalinclude:: upgrade_migrations/001.php
You can use to following table to search & replace your old CI3 files.
+------------------------------+----------------------------+ | Search | Replace | +==============================+============================+ | extends CI_Migration | extends Migration | +------------------------------+----------------------------+ | $this->dbforge->add_field | $this->forge->addField | +------------------------------+----------------------------+ | $this->dbforge->add_key | $this->forge->addKey | +------------------------------+----------------------------+ | $this->dbforge->create_table | $this->forge->createTable | +------------------------------+----------------------------+ | $this->dbforge->drop_table | $this->forge->dropTable | +------------------------------+----------------------------+