- String and Nullable Field:
- We want a
name
column 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
quantity
column 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_available
column 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_date
column 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
category
column 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
metadata
column 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