laravel 如何创建模式表数据类型 longtext?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16952631/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create schema table datatype longtext?
提问by claudchan
I need some help. Example:
我需要帮助。例子:
$table->text('description');
But, how to code/write, if I want my datatype is 'LONGTEXT' ?
但是,如果我希望我的数据类型是 'LONGTEXT' ,如何编码/编写?
I unable to find documentation on this @ http://laravel.com/docs/schema
我无法找到有关此 @ http://laravel.com/docs/schema 的文档
Thanks!
谢谢!
回答by rmobis
Laravel 4.2 / 5.1+
Laravel 4.2 / 5.1+
Simply use the recently added longText
method.
只需使用最近添加的longText
方法。
Schema::create('posts', function ($table) {
$table->increments('id');
$table->integer('user_id');
// ...
$table->longText('description'); // Typos changed from lognText
// ...
}
Pre-Laravel 4.2 / 5.1
Laravel 4.2 / 5.1 之前的版本
There is no way of doing that with the regular Laravel Schema classes, since it does not implement such type. If you really need it, you could use the Schema class to create the table, and then alter the table using a SQL query to add this field. For instance, you could have:
常规 Laravel Schema 类无法做到这一点,因为它没有实现这种类型。如果确实需要,可以使用 Schema 类创建表,然后使用 SQL 查询更改表以添加此字段。例如,你可以有:
Schema::create('posts', function ($table) {
$table->increments('id');
$table->integer('user_id');
// ...
$table->text('description');
// ...
}
DB::statement('ALTER TABLE `posts` COLUMN `description` `description` LONGTEXT;');
回答by Sanket Sahu
It's available now. From the docs
它现在可用。从文档
$table->longText('description');
回答by Manoj Patidar
You need to simple write datatype long text in place of string
您需要简单地编写数据类型的长文本来代替字符串
Schema::table('table name ', function (Blueprint $table) {
$table->longText('attachments');
});
I have this work for you.
我有这个工作给你。
for more details go through the link https://laravel.com/docs/4.2/schema
有关更多详细信息,请访问链接 https://laravel.com/docs/4.2/schema