Schema
class. Migration files are really just wrappers around the Schema
class as well as a way for Masonite to manage which migrations have run and which ones have not.databases/migrations
directory.--table
and --create
flag:up
method and start adding any of the available methods below to your migration.table.string()
table.string('name', length=181)
table.char()
table.text()
table.longtext()
table.integer()
table.integer('age', length=5)
table.unsigned_integer()
table.unsigned()
unsigned_integer
table.tiny_integer()
table.small_integer()
table.medium_integer()
table.big_integer()
table.increments()
table.tiny_increments()
table.big_increments()
table.binary()
table.boolean()
table.json()
table.jsonb()
table.date()
table.year()
down
method which should reverse whatever was done in the up
method. If you create a table in the up method, you should drop the table in the down method.table.drop_table()
table.drop_table_if_exists()
table.drop_column()
drop_column('column1', 'column2')
table.drop_index()
drop_index('email_index')
table.drop_unique()
table.drop_unique('users_email_unique')
table.drop_foreign()
table.drop_foreign('users_article_id_foreign')
table.rename()
table.rename("user_id", "profile_id", "unsigned_integer")
table.drop_primary()
table.drop_primary('users_id_primary')
-s
flag (short for --show
). This works on the migrate and migrate:rollback commands.Database Seeder
class by:CustomTable is the name of the seeder without "Seeder" suffix. Internally we will run the desired CustomTableSeeder.
table.string('is_admin').after('email')
.table.integer('age').unsigned()
column.CURRENT_TIMESTAMP
modifer.table.string('role_id').primary()
table.string('name').comment("A users name")
table.primary(column)
table.primary(['id', 'email'])
. Also supports a name
parameter to specify the name of the index.table.unique(column)
table.unique(['email', 'phone_number'])
. Also supports a name
parameter to specify the name of the index.table.index(column)
table.index('email')
. Also supports a name
parameter to specify the name of the index.table.fulltext(column)
table.fulltext('email')
. Note this only works for MySQL databases and will be ignored on other databases. Also supports a name
parameter to specify the name of the index.The default primary key is often set to an auto-incrementing integer, but you can use a UUID instead.
on_delete
or on_update
method:on_update
and on_delete
are:name
parameter to change the name of the constraint:.change()
method on it.