migration cheatsheet in laravel
migration cheat-sheet
most commonly used data types of mysql in laravel
int bigint decimal date char->varchar varchar text mediumtext longtext |
important methods:
->nullable() ->unsigned(false) |
note: Consider this number: 123456789.12345 here M is 14 and D is 5 then based on this principle you can set DECIMALS(M,D) for each column based on Their expected maximum values.
ex: an amont is: 10000000.34 rupee so for decimal : decimal(8,2)
Note: after creation table via migration, you can modify column size via another migration, and be sure your DB::statement(“ raw SQL query”) will be mentioned within up() function in migration.
ex: i have create a migration file as name “table1_modify”
public function up(): void { DB::statement("ALTER TABLE table1 MODIFY enrollno bigint(20)"); DB::statement("ALTER TABLE table1 MODIFY name varchar(200)"); DB::statement("ALTER TABLE table1 MODIFY age int(100)"); DB::statement("ALTER TABLE table1 MODIFY fees decimal(8,2)"); DB::statement("ALTER TABLE table1 MODIFY gender varchar(1)"); } |
according to me, try to change columns values like int,bigint,varchar & decimal.
------------------------------------------------------------------------------------------------------------------------