Php 如何创建模式表数据类型longtext?
我需要一些帮助。 例如: 但是,如果我希望我的数据类型是“LONGTEXT”,那么如何编码/编写呢 我找不到有关此的文档@ 谢谢 拉威尔4.2/5.1+ 只需使用最近添加的Php 如何创建模式表数据类型longtext?,php,laravel,schema,laravel-4,Php,Laravel,Schema,Laravel 4,我需要一些帮助。 例如: 但是,如果我希望我的数据类型是“LONGTEXT”,那么如何编码/编写呢 我找不到有关此的文档@ 谢谢 拉威尔4.2/5.1+ 只需使用最近添加的longText方法即可 Schema::create('posts', function ($table) { $table->increments('id'); $table->integer('user_id'); // ... $table->longText('des
longText
方法即可
Schema::create('posts', function ($table) {
$table->increments('id');
$table->integer('user_id');
// ...
$table->longText('description');
// ...
}
前拉维4.2/5.1
使用常规的Laravel模式类无法实现这一点,因为它没有实现这样的类型。如果确实需要,可以使用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;');
现在可以用了。从文件中
$table->longText('description');
您需要编写简单的数据类型长文本来代替字符串
Schema::table('table name ', function (Blueprint $table) {
$table->longText('attachments');
});
我有这项工作给你
有关更多详细信息,请访问链接
需要有一个拉取请求才能生成
->longtext
和->mediumtext
方法,我已经多次遇到过这些方法。@MichaelCalkins如果您认为这很有用,请在他们的存储库中打开一个关于建议的问题。应该是DB::statement('ALTER TABLEposts
CHANGEdescription
descriptionLONGTEXT;');现在不需要DB::语句。因为laravel已经提供了$TABLE->LONGTEXT('description');LONGTEXT等效列。请参考@Yagneshbhalala,感谢您指出这一点。更新了答案以反映这一点。
Schema::table('table name ', function (Blueprint $table) {
$table->longText('attachments');
});
Schema::table('table_namae', function (Blueprint $table) {
$table->longText('column_name');
});