CodeIgniter Forums
How to create more than 1 table in Migration? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forum-11.html)
+--- Thread: How to create more than 1 table in Migration? (/thread-78369.html)



How to create more than 1 table in Migration? - mshahrim - 01-09-2021

I followed the guideline here: 

Database Manipulation and Database Forge
https://codeigniter4.github.io/CodeIgniter4/dbmgmt/forge.html

I managed to run the migration, and successfully created 1 table with necessary fields.
All files are duly placed inside app/Database/Migrations.

So my questions right now are;
1. How to create more than 1 table? (in just 1 Migration file)
2. What is really up() and down() for? (is it a must? can I write a custom method instead?) 

Thank you.


#codeigniter4
#forge
#migration


RE: How to create more than 1 table in Migration? - InsiteFX - 01-09-2021

You just continue on like you did the first one repeating for all the tables you need

(up)
Add fields
Add Keys
Create table

Add fields
Add Keys
Create table

(down)
List of tables

Like so.


RE: How to create more than 1 table in Migration? - pankaj11 - 01-25-2021

Yes, migrations can do multiple DB modifications (add tables, drop tables, add indexes, etc).

It is not considered bad form. Migration is a collection of steps necessary to upgrade/downgrade your database to the next/previous format, respectively

Schema::create('users', function($table)
{
$table->increments('id');
});

Schema::create('rights', function($table)
{
$table->increments('id');
});