Laravel Schema Builder:创建一个binary(16)列 [英] Laravel Schema Builder : Creating a binary(16) column
问题描述
使用Laravel 5.5和Mysql(10.1.19-MariaDB)
Using Laravel 5.5 and Mysql (10.1.19-MariaDB)
对于md5哈希,我想要一个binary(16)列.我们称该列为 url_hash
For a md5 hash I want a binary(16) column. Let's call the colum url_hash
使用时:
$table->binary('url_hash');
它将给我一个BLOB列.
it will give me a BLOB column.
源: https://laravel.com/docs/5.5/migrations#creating-列
我已经在网络上看到过各种各样的黑客或插件,但是没有任何可能在下一次更新时中断的外部插件的最简单的是什么?
I have seen all kind of hacks or plugins around the web for this , but what is the most simple one without any external plugins that could break on the next update?
欢呼
推荐答案
Laravel作者推荐进行 DB:statement
调用并运行原始SQL.
Laravel author recommends to do a DB:statement
call and run the raw SQL.
如果您正在运行迁移,则可以在 Schema :: create
:
If you are running migration, you could run this raw SQL after Schema::create
:
DB::statement('ALTER TABLE table_name ADD url_hash binary(16) AFTER some_column');
根据用例,您可能需要运行以下原始SQL来删除列,然后再删除表:
Depends on use case, you could need to run this raw SQL to drop the column before dropping the table:
DB::statement('ALTER TABLE table_name DROP url_hash');
这篇关于Laravel Schema Builder:创建一个binary(16)列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!