
For example, the following migration creates a flights table: id() Īs you may have noticed in the example above, Laravel will automatically assign a class name to all of the migrations that you generate using the make:migration command. To learn about all of the methods available on the Schema builder, check out its documentation. Within both of these methods, you may use the Laravel schema builder to expressively create and modify tables.

The up method is used to add new tables, columns, or indexes to your database, while the down method should reverse the operations performed by the up method.

Schema dumps may not be restored to in-memory SQLite databases.Ī migration class contains two methods: up and down. Migration squashing is only available for the MySQL, PostgreSQL, and SQLite databases and utilizes the database's command-line client. The given path should be relative to your application's base path. If you would like to specify a custom path for the generated migration, you may use the -path option when executing the make:migration command. Otherwise, you may simply specify the table in the migration file manually. If Laravel is able to determine the table name from the migration name, Laravel will pre-fill the generated migration file with the specified table. Laravel will use the name of the migration to attempt to guess the name of the table and whether or not the migration will be creating a new table. Each migration filename contains a timestamp that allows Laravel to determine the order of the migrations: php artisan make:migration create_flights_table The new migration will be placed in your database/migrations directory. You may use the make:migration Artisan command to generate a database migration. Typically, migrations will use this facade to create and modify database tables and columns.

The Laravel Schema facade provides database agnostic support for creating and manipulating tables across all of Laravel's supported database systems. If you have ever had to tell a teammate to manually add a column to their local database schema after pulling in your changes from source control, you've faced the problem that database migrations solve. Migrations are like version control for your database, allowing your team to define and share the application's database schema definition.
