Laravel make model with migration

LaravelLaravel 5Database Migration

Laravel Problem Overview


I'm creating a model on the Laravel 5 with this command:

php artisan make:model Settings

As it shows on the video lessons that as soon as model is created, new migration file also must be created. But, in my situtation, migration is not being created. How can I get the migration generated when model is created?

composer.json:

...
    "require": {
            "php": ">=5.5.9",
            "laravel/framework": "5.1.*"
        },
...

Laravel Solutions


Solution 1 - Laravel

I'm guessing your build of L5 is fairly old, as they disabled creating migrations alongside the model creation.

Try running the ff:

php artisan make:model Settings --migration

Solution 2 - Laravel

Try using this Command

php artisan make:model ModelName -m

OR

php artisan make:model ModelName --migration

It will create model with migration class

Solution 3 - Laravel

Also you can use this command:

    php artisan make:model ModelName -m

and if you wanna make controller for your model, you should write this command :

   php artisan make:model ModelName -mc
   
   // or 

   php artisan make:model ModelName -mcr  //(r: for resource methods)

Solution 4 - Laravel

2020 update:

You can now do:

php artisan make:model ModelName -a

To create a:

  1. model
  2. controller
  3. seeder
  4. migration
  5. factory

All using one command.

Solution 5 - Laravel

You can use the make:model flags like;

php artisan make:model Setting -m

enter image description here

Help: php artisan make:model --help

Solution 6 - Laravel

php artisan make:model Image -m Create Migration, Model file

php artisan make:model Image -mcr Create Migration, Model, Controller with resource

Solution 7 - Laravel

It's weird because to skip migration you could use the flag --no-migration. That means that calling php artisan make:model Foo should automatically create everything. Does artisan show any errors? Did you check logs? What Laravel version are you using? 5? 5.1?

Solution 8 - Laravel

If you would like to generate a database migration when you generate the model, you may use the --migration or -m option

php artisan make:model Settings --migration

php artisan make:model Settings -m

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionnsvView Question on Stackoverflow
Solution 1 - LaraveldavspView Answer on Stackoverflow
Solution 2 - LaravelAshishView Answer on Stackoverflow
Solution 3 - LaravelHamid TeimouriView Answer on Stackoverflow
Solution 4 - LaravelWouter DorgeloView Answer on Stackoverflow
Solution 5 - LaravelbmatovuView Answer on Stackoverflow
Solution 6 - LaravelJatnielView Answer on Stackoverflow
Solution 7 - LaravelMatt KomarnickiView Answer on Stackoverflow
Solution 8 - LaravelRayees PkView Answer on Stackoverflow