Laravel 从现有模型生成迁移
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47649813/
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
Laravel Generate Migration from existing Model
提问by Ники Арсов
How can I create migration file from existing model in Laravel or model from existing migration?
如何从 Laravel 中的现有模型或现有迁移模型创建迁移文件?
采纳答案by lagbox
For the model, just create a model, there isn't anything special, just make sure to set the $tableif not following convention.
对于模型,只要创建一个模型,没有什么特别的,只要确保设置$tableif不遵循约定即可。
For generating migrations from an existing Database schema there is a package:
为了从现有数据库模式生成迁移,有一个包:
回答by Blasanka
To create a table for a existing Model, you just have to run below command,
要为现有模型创建表,您只需运行以下命令,
php artisan make:migration table_name
and, go to the database -> migration -> date_with-table_name
并且,去 database -> migration -> date_with-table_name
inside up(), type your table name and fields that you want to add, something like belowa;
在里面up(),输入你想要添加的表名和字段,如下所示;
Schema::create('table_name', function (Blueprint $table) {
$table->increments('id');
$table->string('field_2');
$table->string('field_3');
$table->string('field_4');
$table->date('field_5');
$table->string('field_6');
$table->timestamps();
});
回答by Kuldeep Mishra
php artisan make:migration create_users_table
your Model name will be User and the table name will be users
您的模型名称将是用户,表名称将是用户
回答by jacobdo
Model and migration are merely connected through naming convention. Models and migrations are created separately.
模型和迁移仅通过命名约定连接。模型和迁移是分开创建的。

