

Laravel's schema builder blueprint class provides methods for creating each type of index supported by Laravel. $table -> unique ( ' email ', ' unique_email ' ) To create the index, we can chain the unique method onto the column definition: The following example creates a new email column and specifies that its values should be unique. The Laravel schema builder supports several types of indexes. Each of these methods is described in the table below: Commandĭrop the morphable_id and morphable_type columns.ĭrop the created_at and updated_at columns. Laravel provides several convenient methods related to dropping common types of columns. Dropping or modifying multiple columns within a single migration while using this package is not supported.
#MYSQL ADD COLUMN TO TABLE AFTER ANOTHER COLUMN INSTALL#
If you are running a version of SQLite prior to 3.35.0, you must install the doctrine/dbal package via the Composer package manager before the dropColumn method may be used. One situation where this is particularly useful is when you need to assign default values to JSON columns: Using an Expression instance will prevent Laravel from wrapping the value in quotes and allow you to use database specific functions. The default modifier accepts a value or an Illuminate\Database\Query\Expression instance. Set spatial column type to geometry - the default type is geography (PostgreSQL). Set TIMESTAMP columns to use CURRENT_TIMESTAMP when a record is updated (MySQL).Ĭreate a virtual generated column (MySQL).Ĭreate an identity column with specified sequence options (PostgreSQL).ĭefines the precedence of sequence values over input for an identity column (PostgreSQL). Set TIMESTAMP columns to use CURRENT_TIMESTAMP as default value. Make the column "invisible" to SELECT * queries (MySQL).Īllow NULL values to be inserted into the column.Ĭreate a stored generated column (MySQL / PostgreSQL). Set the starting value of an auto-incrementing field (MySQL / PostgreSQL). Place the column "first" in the table (MySQL). Specify a "default" value for the column.

Specify a collation for the column (MySQL/PostgreSQL/SQL Server).Īdd a comment to a column (MySQL/PostgreSQL). Specify a character set for the column (MySQL). Set INTEGER columns as auto-incrementing (primary key). Place the column "after" another column (MySQL). This list does not include index modifiers: Modifier The following table contains all of the available column modifiers. To get started, execute the schema:dump command: If you would like, you may "squash" your migrations into a single SQL file. This can lead to your database/migrations directory becoming bloated with potentially hundreds of migrations. Migration stubs may be customized using stub publishing.Īs you build your application, you may accumulate more and more migrations over time. 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. Php artisan make:migration create_flights_table Each migration filename contains a timestamp that allows Laravel to determine the order of the migrations: 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.
