如果我有一些具有非默认特性(如软删除或自定义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();
});
} ...发布于 2018-09-14 21:07:56
在正常开发中,迁移先于模型细节。迁移包含模式定义,而不是模型。雄辩的模型遵循活动记录模式,不包含列的类型定义。如果遵循命名约定,则不需要指定模型中有关表或列的任何内容。
有关make:迁移的命令不会从现有模型或数据库表中提取任何内容。有一个包支持从现有数据库模式创建迁移:https://github.com/Xethron/migrations-generator,而不是模型本身。
https://stackoverflow.com/questions/52339124
复制相似问题