- String and Nullable Field:
- We want a
namecolumn to store product names. It should be a string and nullable (i.e., it can be empty).
- We want a
php artisan make:migration create_products_table --create=products --schema="name:string:nullable"- Integer Field with Default Value:
- We’ll add an
quantitycolumn to store the product quantity. It’s an integer with a default value of 0.
- We’ll add an
php artisan make:migration create_products_table --create=products --schema="name:string:nullable, quantity:integer:default(0)"- Boolean Field:
- Let’s include an
is_availablecolumn to indicate whether the product is currently available (true or false).
- Let’s include an
php artisan make:migration create_products_table --create=products --schema="name:string:nullable, quantity:integer:default(0), is_available:boolean"- Date Field:
- We’ll add a
release_datecolumn to store the product release date.
- We’ll add a
php artisan make:migration create_products_table --create=products --schema="name:string:nullable, quantity:integer:default(0), is_available:boolean, release_date:date"- Enum Field:
- Suppose we want a
categorycolumn to represent product categories (e.g., “Electronics,” “Clothing,” “Books”).
- Suppose we want a
php artisan make:migration create_products_table --create=products --schema="name:string:nullable, quantity:integer:default(0), is_available:boolean, release_date:date, category:enum('Electronics', 'Clothing', 'Books')"- JSON Field:
- We’ll add a
metadatacolumn to store additional product information in JSON format.
- We’ll add a
php artisan make:migration create_products_table --create=products --schema="name:string:nullable, quantity:integer:default(0), is_available:boolean, release_date:date, category:enum('Electronics', 'Clothing', 'Books'), metadata:json"Remember to adjust the field names and types according to your specific use case. After creating the migration, run php artisan migrate to apply it to your database. Happy coding!
For more details, you can refer to the official Laravel documentation on migrations

