0
我已经有一个数据库设置,我想创建从空数据库到当前状态的迁移。迁移处理不支持的类型
如何通过Laravel迁移来处理不受支持的类型(如Point)?
唯一我能想到的解决方案是使用DB::statement
并编写原始SQL。有没有更好的方法?
此外,是否有任何转换器从现有的数据库到Laravel迁移,正确处理这些不受支持的类型?
我已经有一个数据库设置,我想创建从空数据库到当前状态的迁移。迁移处理不支持的类型
如何通过Laravel迁移来处理不受支持的类型(如Point)?
唯一我能想到的解决方案是使用DB::statement
并编写原始SQL。有没有更好的方法?
此外,是否有任何转换器从现有的数据库到Laravel迁移,正确处理这些不受支持的类型?
有一个包,能为你做到这一点:https://github.com/shiftonelabs/laravel-nomad/
它有与此签名的函数:
public function passthru($realType, $column, $definition = null)
{
return $this->addColumn('passthru', $column, compact('realType', 'definition'));
}
,用于像
class CreateUsersTable extends Migration {
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->increments('id');
$table->passthru('citext', 'name');
$table->passthru('citext', 'title')->nullable();
$table->passthru('string', 'email', 'varchar(255)')->unique();
$table->passthru('string', 'password')->definition('varchar(60)');
$table->rememberToken();
$table->timestamps();
});
}
public function down()
{
Schema::drop('users');
}
}
它扩展了BaseBlueprint类并使用该功能addColumn
https://laravel.com/api/5.2/Illuminate/Database/Schema/Blueprint.html#method_addColumn
你能解释一下不支持的类型吗? –
@SagarGautam请看看可用的列类型:https://laravel.com/docs/5.4/migrations – metalcamp
@metalcamp所以,你有其他类型的列数据 –