laravel artisan migrate 命令不迁移,不产生任何输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41702650/
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
artisan migrate command doesn't migrate, produces no output
提问by Jay Bienvenu
I am working on my first Laravel project. I'm trying to create database migrations and run them with artisan migrate
. The migrations aren't running and the command returns no output.
我正在做我的第一个 Laravel 项目。我正在尝试创建数据库迁移并使用artisan migrate
. 迁移未运行,命令不返回任何输出。
Key facts:
关键事实:
- I used
artisan make:migration
to create the migration file with the proper filepath. - The first time I ran the command, it created the migration table in the database. So I know that it is hitting the database and at least doing something right.
- When I have no files in the
database/migrations
folder, I get theNothing to migrate
command. - Beyond these two messages, I have received no output at all from the command. No errors, nothing. Furthermore, there are no records in the migration table in the database.
artisan migrate --verbose
also returns no output.- The permissions on
storage/logs
isdrwxrwxrwx.
I am the owner of the directory. storage/logs/laravel.log
doesn't contain anything pertaining to the migrations.
- 我曾经使用
artisan make:migration
正确的文件路径创建迁移文件。 - 我第一次运行该命令时,它在数据库中创建了迁移表。所以我知道它正在访问数据库并且至少做了一些正确的事情。
- 当文件
database/migrations
夹中没有文件时,我会收到Nothing to migrate
命令。 - 除了这两条消息之外,我根本没有从命令中收到任何输出。没有错误,什么都没有。此外,数据库中的迁移表中没有记录。
artisan migrate --verbose
也不返回任何输出。- 权限
storage/logs
是drwxrwxrwx.
我是目录的所有者。 storage/logs/laravel.log
不包含任何与迁移有关的内容。
I've included the code for my first migration below.
我在下面包含了我第一次迁移的代码。
This question is different from this questionin that the previous user didn't use the proper naming convention. That question contains a detailed answer about the migration process. It's not helpful because I'm not getting any output. I also reviewed the questions suggested by SO as I entered this question.
这个问题与这个问题的不同之处在于之前的用户没有使用正确的命名约定。该问题包含有关迁移过程的详细答案。这没有帮助,因为我没有得到任何输出。当我输入这个问题时,我还查看了 SO 建议的问题。
Perhaps I have something configured incorrectly? What do I need to do to get these migrations running?
也许我配置不正确?我需要做什么才能运行这些迁移?
2017_01_17_151638_user.php
2017_01_17_151638_user.php
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
// Create the classes associated with user management.
class UserMigration extends Migration
{
public function up()
{
Schema::create('tblUser', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
Schema::create('tblUserPasswordReset', function (Blueprint $table) {
$table->string('email')->index();
$table->string('token')->index();
$table->timestamp('create_date')->nullable();
});
}
public function down()
{
Schema::dropIfExists('tblUserPasswordReset');
Schema::dropIfExists('tblUser');
}
}
回答by ATechGuy
try
尝试
php artisan migrate:rollback
then try
然后尝试
php artisan migrate
Laravel keeps track of the migrations ran, so if you have run it before, it knows and wont do it again unless you roll it back and I ran into this until i rolled them back and then ran migrate again
Laravel 会跟踪运行的迁移,所以如果你之前运行过它,它知道并且不会再次运行,除非你回滚它,我遇到了这个,直到我回滚它们然后再次运行迁移
回答by acubcn
For me the only way to make it work was by restarting the mysql service (in OSX, never saw this on debian).
对我来说,让它工作的唯一方法是重新启动 mysql 服务(在 OSX 中,从未在 debian 上看到过)。
回答by Tim
I am pretty sure I just figured out the problem.
我很确定我刚刚找到了问题所在。
I created a new user in MySQL and assigned all rights to all databases through the mysql shell:
我在 MySQL 中创建了一个新用户,并通过 mysql shell 为所有数据库分配了所有权限:
CREATE USER 'user1'@'localhost' IDENTIFIED BY 'password';
GRANT ALL ON *.* to 'user1'@'localhost';
Don't forget to change the connection info in .env:
不要忘记更改 .env 中的连接信息:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=blog
DB_USERNAME=user1
DB_PASSWORD=password
回答by abokor hassan
i had this issue earlier this month what i did was i checked the confiuration to mysql server carefully the restart the mysql server and the IDE itself
本月早些时候我遇到了这个问题,我所做的是我仔细检查了 mysql 服务器的配置,然后重新启动了 mysql 服务器和 IDE 本身
回答by Carlos Adames
Do not miss to add your migrations to DatabaseSeeder.php. Refer to this documentation Calling Additional Seeders.
不要错过将您的迁移添加到 DatabaseSeeder.php。请参阅此文档调用其他播种机。
Within the DatabaseSeeder add this:
在 DatabaseSeeder 中添加以下内容:
$this->call(UserMigration::class);
Hope it helps.
希望能帮助到你。
回答by Chris Hoban
Had this exact problem with none of the listed solutions changing anything. The unmentioned solution that works in this case for me was
遇到了这个确切的问题,列出的解决方案都没有改变任何东西。在这种情况下对我有用的未提及的解决方案是
composer update --no-scripts
I had wiped out everything and was starting from scratch, forgot to re init composer and install everything.
我已经清除了所有内容并从头开始,忘记重新初始化作曲家并安装所有内容。
回答by Marc
The only way I have been able to reproduce a case where Migrations run without error yet do not migrate is by having not specified a database schema name in the config along with a connection name.
我能够重现迁移运行没有错误但不迁移的情况的唯一方法是没有在配置中指定数据库模式名称和连接名称。
In either in the .envfile ensure that the following settings has a value:
在.env文件中,确保以下设置具有值:
DB_CONNECTION=master
DB_DATABASE=my_databse_name
or alternatively in /config/database.php:
或者在/config/database.php 中:
'default' => env('DB_CONNECTION', 'master'),
'connections' => [
'master' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'my_databse_name'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => 'cms_',
'strict' => true,
'engine' => null,
],
],
回答by Chris
Double check the following:
仔细检查以下内容:
- Migration files are actually being created in
database/migrations
- Double check the log file and directory is writable
- Make sure the permissions on the
database/migrations
folders are the default that come with the laravel install - Doublecheck the laravel.log file
- 迁移文件实际上是在
database/migrations
- 仔细检查日志文件和目录是否可写
- 确保
database/migrations
文件夹的权限是 Laravel 安装附带的默认权限 - 仔细检查 laravel.log 文件
回答by Uzair
- First check your Services Apache and Mysql running by going to your localhost/phpmyadmin.
- check your terminal or cmd that you are in correct filepath directory.
- then write php artisan migrate
- if something shows let me know here if not goto your laravel.log for details
- 首先通过访问您的 localhost/phpmyadmin 检查您的服务 Apache 和 Mysql 正在运行。
- 检查您的终端或 cmd 您是否在正确的文件路径目录中。
- 然后写php artisan migrate
- 如果有什么显示,请在此处告诉我,如果没有,请访问您的 laravel.log 以获取详细信息
回答by Paras
Try:composer dump-autoload
尝试:composer dump-autoload
Then run php artisan migrate
again
然后php artisan migrate
再次运行
Possible issue: https://stackoverflow.com/a/33974248/7377984