php Laravel 和 InnoDB
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11358849/
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
Laravel & InnoDB
提问by DigitalWM
I am using laravel and laravel migration mechanism. I created tables and seted up foreign keys. But the tables are MyISSAM so no foreign keys are created. Where do I enable / configure this? (to change it to InnoDB and not in the mysql server).
我正在使用 laravel 和 laravel 迁移机制。我创建了表并设置了外键。但是这些表是 MyISSAM,所以没有创建外键。我在哪里启用/配置它?(将其更改为 InnoDB 而不是在 mysql 服务器中)。
回答by Thomas LAURENT
You can edit your /config/database.php file, search for mysqlentry and change:
您可以编辑您的 /config/database.php 文件,搜索mysql条目并更改:
'engine' => null,
'engine' => null,
to
到
'engine' => 'InnoDB',
'engine' => 'InnoDB',
This saves you from adding $table->engine = "InnoDB";for each of your Schemas ;)
这$table->engine = "InnoDB";使您无需为每个架构添加;)
回答by srsajid
Define engine like this
像这样定义引擎
Schema::create("models", function(Blueprint $table) {
$table->engine = "InnoDB";
}
回答by crynobone
You can set the engine inside Schema\Table closure.
您可以在Schema\Table 闭包中设置引擎。
回答by Akash
I would recommend to update your Mysql to 5.5 or higher. The default storage engine for Mysql now is InoDB
我建议将您的 Mysql 更新到 5.5 或更高版本。Mysql 的默认存储引擎现在是 InoDB
Before MySQL 5.5.5, MyISAM is the default storage engine. (The default was changed to InnoDB in MySQL 5.5.5.) MyISAM is based on the older (and no longer available) ISAM storage engine but has many useful extensions.
在 MySQL 5.5.5 之前,MyISAM 是默认的存储引擎。(在 MySQL 5.5.5 中默认更改为 InnoDB。)MyISAM 基于旧的(不再可用)ISAM 存储引擎,但有许多有用的扩展。
http://dev.mysql.com/doc/refman/5.5/en/myisam-storage-engine.html
http://dev.mysql.com/doc/refman/5.5/en/myisam-storage-engine.html
Once done, you can easily map relationships within the entity classes via Laravel
完成后,您可以通过 Laravel 轻松映射实体类中的关系
回答by Yousef Altaf
I found @ThomasLAURENT is the best solution but what about the existing tables I have in my database.
我发现@ThomasLAURENT 是最好的解决方案,但是我数据库中的现有表呢?
Working around.
工作。
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class ConvertTablesIntoInnoDB extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$tables = [
'users',
'products',
];
foreach ($tables as $table) {
DB::statement('ALTER TABLE ' . $table . ' ENGINE = InnoDB');
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
$tables = [
'users',
'products',
];
foreach ($tables as $table) {
DB::statement('ALTER TABLE ' . $table . ' ENGINE = MyISAM');
}
}
}
This will allow us to convert all the tables and roll-back them when I need.
这将允许我们转换所有表并在需要时回滚它们。
回答by Tiago Gouvêa
Another approach (for whose that don't uses database.php) is to include on .envfile:
另一种方法(不使用 database.php 的方法)是包含在.env文件中:
DB_ENGINE=InnoDB
DB_ENGINE=InnoDB
Remember to check if you have 'engine' => env('DB_ENGINE', null),on your database.php
记得检查'engine' => env('DB_ENGINE', null),你的database.php是否有
回答by RDK
Use InnoDb tables on the server side it's best way to success. Use MySQL Workbench. It easy in Workbench. And, if you want read the native manual
在服务器端使用 InnoDb 表是成功的最佳方式。使用MySQL 工作台。在 Workbench 中很容易。而且,如果您想阅读本机手册
回答by Huy Nguy?n
Schema::create('users', function($table)
{
$table->engine = 'InnoDB';
$table->string('email');
});
Like document Laravel: https://laravel.com/docs/4.2/schema#storage-engines
喜欢文档 Laravel:https://laravel.com/docs/4.2/schema#storage-engines
P/s: Thanks @Nico Haase for reminding me to provide the link.
P/s:感谢@Nico Haase 提醒我提供链接。

