Request a FREE Quote

Websites have become more demanding for businesses, now-a-days they deliver more values than past years. 根据报告 w3techs, PHP – Most admired scripting language for frontend and backend which is widely used as compared to other programming languages. Around 77% of all the websites on the internet are developed in PHP and other PHP开发框架.
When the time comes to decide with which PHP framework one should go for web development projects, 这应该是一个容易决定的任务. 借助这些PHP框架 网站开发 任务可以是多种多样的 & faster. Amongst them, CodeIgniter is one of the most widely used PHP frameworks.
Modern day programming is used for developing large scale projects nowadays and the work is distributed under several developers. Each of them have to work with either a separate database or work on the same Database. And the developers need to change and also keep track of the database for the same project. In this case database migration comes in picture.
Database migrations in Codeigniter-4 are used to track and run the changes of the database with the help of Command Line Interface with the help of Spark. Spark is the built-in official commands provided by Codeigniter-4.
See Also: Developers’ guide for establishing and adhering to Coding Standards
These are some of the most used database migration spark commands used in Codeigniter-4. Open the project directory in Command Prompt and run the following commands:
This automatically creates the migration file for the project under 应用程序/数据库/迁移/ 项目中的目录.
Example:
php spark make:migration Testmigrate . php
In this file there are mainly two functions
Example:
公共功能up()
{
$this->forge->addField([
'blog_unique_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'auto_increment' => true,
],
'blog_title' => [
'type' => 'VARCHAR',
'constraint' => '150',
],
'blog_details' => [
'type' => 'TEXT',
'null' => true,
],
]);
$this->forge->addKey(blog_unique_id, true);
$this->forge->createTable('tbl_blog');
}
In down() functions handles the rollback operations performs on the database
Example
公共函数down()
{
$this->forge->dropTable('tbl_blog');
}
In the given example the in down method there are dropTable blog for remove table from Database
See Also: 8 Advantages of Custom PHP开发
Migrate command is used to execute the migrations and perform Database Operations. The above command runs and executes all the migrations. 它只执行 up() 方法
The above Command runs and executes the down() 迁移方法.
The above Command Refreshes the database by simply performing rollback first and then the migration. 这意味着它首先执行 down() 方法,然后 up() 迁移方法
It displays the graphical representation of the status of all the migrations
Example
This automatically creates the migration file for the project under 应用程序/数据库/种子/
项目中的目录. 播种机用于
Example:php spark
//Example:
公共函数run()
{
$this->db->table('tbl_blog)->truncate();
$this->db->table('tbl_blog')->insert([
"blog_title" => "hello",
"blog_details" => 'world',
]);
}
在上面的例子中, remove all the fields from Database and then insert a new blog with blog_title of ‘hello’ 和blog_details with ‘world’.
Seed command is used to execute the seeding and perform Database Operations. The above command runs and executes all the seeds at time. This needs the seeder name for the parameter
The above command runs and executes the individual seeds at a time by the file path parameter.
For more details please review official documentation by codeigniter4 Team below.
http://codeigniter4.github.io/userguide/dbmgmt/migration.html
你在做什么 CodeIgniter项目 and want to get your database migrated or facing issues while altering the database? SpryBit is here with a solution for you, we have expertise in CodeIgniter发展. 今天就贝博体彩APP下载的专家!
Thank you ojash for valuable information for codeIgniter 4 migration commands.
优秀的文章! Learned valuable tips for migrating data to CodeIgniter 4