Skip to content

7.2 makeMigration

Lucas F. Lu edited this page Jan 31, 2020 · 4 revisions

Command to build a migration

This command helps building a migration file by taking an argument as the table name and performs the migration if needed.

  • Option "datafields" or flag "-D" defines the model fields. It is reaquired and the format for its value is:

    fieldname:dataType(option)[modifier,...]

Example of creating a table called "person", with a nullable, string typed field called "name" and defauts to "John", a set typed field called "gender" with values between "male" and "female" is given below.

Example: php artisan bp:makeMigration person -D="name:string(100)[nullable]<John>;gender:set(male,female)"
  • To perform migration at the end use flag "-M"
  • To specify the engine type, use flag "-E"
  • To specify a default character set for the table, use flag "-C"
  • To specify a default collation for the table, use flag "-O"
  • To automatically add in timestamp fields, use flag "-S"
  • Use flag "-T" to see a list of all available field types
  • Use flag "-F" to see a list of all available modifiers
  • Use flag "-W" to use wizard when creating a migration. When wizard is used, no table name is needed.

List of all available field types

increments
bigIncrements
mediumIncrements
smallIncrements
tinyIncrements
integer
mediumInteger
bigInteger
smallInteger
tinyInteger
unsignedBigInteger
unsignedInteger
unsignedMediumInteger
unsignedSmallInteger
unsignedTinyInteger
binary
boolean
char:option (Size). example => name:char(100)
date
dateTime
dateTimeTz
decimal:option (total digits,decimal digits). example => number:decimal(8,2)
double:option (total digits,decimal digits). example => number:double(8,2)
enum:option (value list seperated by comma ","). example => enums:enum(a,b,c,1,2,3)
float:option (total digits,decimal digits). example => number:float(8,2)
geometry
geometryCollection
ipAddress
json
jsonb
lineString
longText
macAddress
mediumText
morphs
uuidMorphs
multiLineString
multiPoint
multiPolygon
nullableMorphs
nullableUuidMorphs
point
polygon
rememberToken
set:option (value list seperated by comma ","). example => sets:set(a,b,c,1,2,3)
string:option (Size). example => name:string(100)
text
time
timeTz
timestamp
timestampTz
timestamps
timestampsTz
unsignedDecimal:option (total digits,decimal digits). example => number:unsignedDecimal(8,2)
uuid
year

List of all available modifiers

You can seperate each modifiers with comma ","

autoIncrement: Integer type auto-increment
nullable: Allows (by default) NULL values to be inserted into the column
unsigned: Set INTEGER columns as UNSIGNED (MySQL)
useCurrent: Set TIMESTAMP columns to use CURRENT_TIMESTAMP as default value
primary: Set as Primary Key
editable: Make field available for mass assignables