How to run Migration in laravel project for database
1. Basic Migration:
- Assuming you have created migrations using
php artisan make:migration MyMigrationName(replace with your desired name), run the following command to apply all pending migrations:
php artisan migrate
2. Specific Options:
You can utilize various options with the
migratecommand:--pretend: Simulates the migration process without actually making changes to the database (useful for testing).--seed: Runs the database seeders after applying migrations (for adding initial data).--force: Forces the migration to run even if there are potential risks like data loss. Use with caution!
Here are some examples:
php artisan migrate --pretend # Simulate migration
php artisan migrate --seed # Migrate and seed
php artisan migrate --force # Force migration (use carefully)
3. Specific Migrations:
- To run a specific migration by its migration file name:
php artisan migrate --path=database/migrations/MyMigrationName.php
- Replace
MyMigrationName.phpwith the actual filename of the migration you want to run.
4. Resetting Migrations:
- To completely rollback all migrations and start fresh:
php artisan migrate:reset
Remember:
- Ensure you have configured your database connection details correctly in the
.envfile before running any migrations. - Refer to the Laravel documentation for more advanced options and detailed explanations: https://laravel.com/docs/10.x/migrations

Comments
Post a Comment