如果我有一些模型,具有非默认功能(如软删除或自定义 ID 名称)并想从中创建一个迁移文件,其中包含所有这些属性,该怎么办?所以这是我的模型:
class Test extends Model
{
use SoftDeletes;
protected $primaryKey = 'test_id';
protected $table = 'my_flights';
protected $dates = ['deleted_at'];
}
我希望我的迁移文件基于它。但是,当我使用命令php artisan make:migration create_test(s)_table
(我同时尝试了test
和tests
)时,也使用了参数,--create
或者--table
我得到了迁移文件,因为没有任何模型:
class CreateTestTable extends Migration
{
public function up()
{
Schema::create('test', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
} ...
在正常开发中,迁移先于模型细节。迁移包含模式定义,而不是模型。Eloquent 模型遵循活动记录模式,不包含列的类型定义。如果遵循命名约定,则无需在模型中指定有关表或列的任何内容。
make:migration 命令不会从现有模型或数据库表中提取任何内容。有一个包支持从现有数据库模式创建迁移:https : //github.com/Xethron/migrations-generator但不支持从模型本身创建迁移。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句