mysql - 迁移处理不支持的类型

标签 mysql laravel mariadb database-migration

我已经有一个数据库设置,我想创建从空数据库到当前状态的迁移。

如何处理 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

关于mysql - 迁移处理不支持的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45461479/

相关文章:

php - 将jquery mobile和php mysql转为apk文件

mysql - 过滤 mysql 数据透视查询而不丢失所选记录的过滤字段

PHP,如何检查查询是否成功运行,否则重定向到其他页面而不显示错误

php - 使用分页在 Codeigniter 中使用复选框删除

javascript - Laravel 按 href 提交删除表单

mysql - 无法在 php artisan migrate 上连接到 mysql

mysql - 有没有更好的方法将 MySQL GROUP_CONCAT 输出拆分为多行?例如说每六 (6) 条记录后

mysql - 外键引用复合主键

php - 拉拉维尔 5 : removing a record from a pivot table with routing issue - NotFoundHttpException

mysql - 使用 INSERT ... SELECT 防止锁等待超时