Laravel 使用迁移制作模型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31739871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 17:05:02  来源:igfitidea点击:

Laravel make model with migration

laravellaravel-5database-migration

提问by Sarvar Nishonboev

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

我正在使用以下命令在 Laravel 5 上创建模型:

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:

作曲家.json:

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

回答by davsp

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

我猜您的 L5 版本相当旧,因为它们禁止在创建模型的同时创建迁移。

Try running the ff:

尝试运行 ff:

php artisan make:model Settings --migration

回答by Ashish

Try using this Command

尝试使用此命令

php artisan make:model Model_Name -m

OR

或者

php artisan make:model Model_Name --migration

It will create migration with function

它将创建具有功能的迁移

回答by hamidteimouri

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)

回答by bmatovu

You can use the make:modelflags like;

您可以使用以下make:model标志;

php artisan make:model Setting -m

php artisan make:model Setting -m

enter image description here

在此处输入图片说明

Help: php artisan make:model --help

帮助: php artisan make:model --help

回答by Rayees Pk

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

如果您想在生成模型时生成数据库迁移,可以使用 --migration 或 -m 选项

php artisan make:model Settings --migration

php artisan make:model 设置 --migration

php artisan make:model Settings -m

php artisan make:model 设置 -m

回答by Matt Komarnicki

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

这很奇怪,因为要跳过迁移,您可以使用 flag --no-migration。这意味着调用php artisan make:model Foo应该自动创建一切。工匠是否显示任何错误?你检查日志了吗?你使用的是什么 Laravel 版本?5?5.1?