laravel 8 migration error: Unknown column 'batch' in 'order clause' (SQL: select `migration` from `migrations` order by `batch` asc, `migration` asc)
laravel 8 migration error: Unknown column 'batch' in 'order clause' (SQL: select `migration` from `migrations` order by `batch` asc, `migration` asc)
[已解决]
我是 Laravel 和 PHP 的新手。
我试图迁移我自己的迁移,但我不能。
这是我的 laravel 和 php 信息:
我的php信息
PHP 8.0.3 (cli) (built: Mar 4 2021 05:33:14) ( NTS )
Composer version 2.0.11 2021-02-24
Laravel 8.x
mysql
Server version: 10.5.9-MariaDB Arch Linux
我的OS信息
- uname:
Linux ali 5.4.105-1-MANJARO #1 SMP PREEMPT 2021 x86_64 GNU/Linux
当我 运行 命令 ./artisan migrate
或 php artisan migrate
Laravel 抛出此错误时:
Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'batch' in 'order clause' (SQL: select `migration` from `migrations` order by `batch` asc, `migration` asc)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:687
683▕ // If an exception occurs when attempting to run a query, we'll format the error
684▕ // message to include the bindings with SQL, which will make this exception a
685▕ // lot more helpful to the developer instead of just the database's errors.
686▕ catch (Exception $e) {
➜ 687▕ throw new QueryException(
688▕ $query,
689▕ $this->prepareBindings($bindings),
690▕ $e
691▕ );
• A column was not found: You might have forgotten to run your migrations. You can run your migrations using `php artisan migrate`.
https://laravel.com/docs/master/migrations#running-migrations
+28 vendor frames
29 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
无论我的迁移文件如何,它总是在我的系统上发生。
这意味着如果我在连一个迁移文件都没有的情况下迁移我的应用程序,就会出现此错误。
例如,我使用以下步骤创建项目:
composer create-project laravel/laravel mig "8.x"
此问题已在 8.x、7.x、6.x 版本上测试。
cd mig
更改我的 .env
文件并设置以下变量:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME="my database"
DB_PASSWORD="my pasword"
这是我的 .env 文件:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:J2//xlOZPYFlkzQwWmuwbILklCmPnTV6beXFED48K4I=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME="my database"
DB_PASSWORD="my pasword"
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
如果我输入不正确的密码或我的数据库和用户名,我将收到此错误:
Illuminate\Database\QueryException
SQLSTATE[HY000] [1045] Access denied for user 'database'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
+33 vendor frames
34 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
但是当我写入正确的数据库信息时总是 Laravel 抛出这个错误:
Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'batch' in 'order clause' (SQL: select `migration` from `migrations` order by `batch` asc, `migration` asc)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
• A column was not found: You might have forgotten to run your migrations. You can run your migrations using `php artisan migrate`.
https://laravel.com/docs/master/migrations#running-migrations
+27 vendor frames
28 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
此错误和问题仅针对迁移系统。
在我的应用程序查询生成器中,Eloquent Laravel 运行良好。
在我的错误中它说:
• A column was not found: You might have forgotten to run your migrations. You can run your migrations using `php artisan migrate`.
但它不起作用,为什么?
解决方案
这是我的 mysql tables :
+-------------------+
| Tables_in_laravel |
+-------------------+
| migrations |
+-------------------+
migrations
table 已经存在于我的数据库中,但它是自定义迁移 table。
实际上这个 table 是由另一个框架创建的...
https://github.com/alirezaarzehgar/my-exercise-php-framework.git
我在许多网络应用程序中使用 signal@localhost mysql 用户,此操作产生了冲突。
这是我的解决方案:
首先,您应该删除当前 mysql 用户的所有 table。
在这种情况下,我只有 migrations
table :
mysql -u username -p'password' databse -e "DROP TABLE migrations"
如果你想查看你所有的迁移,你可以运行这个命令:
mysql -u username -p'password' databse -e "SHOW TABLES"
然后你可以删除所有这些table。
然后您可以 运行 您的迁移。
./artisan migrate
更改您的 'db_database' 希望您的问题能够解决
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=root
DB_PASSWORD=
删除旧的迁移table 然后重新运行 artisan migrate 看看会发生什么
首先,您应该删除当前 mysql 用户的所有 table。
在这种情况下,我只有 migrations
table :
mysql -u username -p'password' databse -e "DROP TABLE migrations"
如果您想查看所有迁移,可以运行此命令:
mysql -u username -p'password' databse -e "SHOW TABLES"
然后你可以删除所有这些 table。
然后您可以 运行 您的迁移。
./artisan migrate
[已解决]
我是 Laravel 和 PHP 的新手。
我试图迁移我自己的迁移,但我不能。
这是我的 laravel 和 php 信息:
我的php信息
PHP 8.0.3 (cli) (built: Mar 4 2021 05:33:14) ( NTS )
Composer version 2.0.11 2021-02-24
Laravel 8.x
mysql
Server version: 10.5.9-MariaDB Arch Linux
我的OS信息
- uname:
Linux ali 5.4.105-1-MANJARO #1 SMP PREEMPT 2021 x86_64 GNU/Linux
当我 运行 命令 ./artisan migrate
或 php artisan migrate
Laravel 抛出此错误时:
Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'batch' in 'order clause' (SQL: select `migration` from `migrations` order by `batch` asc, `migration` asc)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:687
683▕ // If an exception occurs when attempting to run a query, we'll format the error
684▕ // message to include the bindings with SQL, which will make this exception a
685▕ // lot more helpful to the developer instead of just the database's errors.
686▕ catch (Exception $e) {
➜ 687▕ throw new QueryException(
688▕ $query,
689▕ $this->prepareBindings($bindings),
690▕ $e
691▕ );
• A column was not found: You might have forgotten to run your migrations. You can run your migrations using `php artisan migrate`.
https://laravel.com/docs/master/migrations#running-migrations
+28 vendor frames
29 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
无论我的迁移文件如何,它总是在我的系统上发生。 这意味着如果我在连一个迁移文件都没有的情况下迁移我的应用程序,就会出现此错误。
例如,我使用以下步骤创建项目:
composer create-project laravel/laravel mig "8.x"
此问题已在 8.x、7.x、6.x 版本上测试。
cd mig
更改我的 .env
文件并设置以下变量:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME="my database"
DB_PASSWORD="my pasword"
这是我的 .env 文件:
APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:J2//xlOZPYFlkzQwWmuwbILklCmPnTV6beXFED48K4I=
APP_DEBUG=true
APP_URL=http://localhost
LOG_CHANNEL=stack
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME="my database"
DB_PASSWORD="my pasword"
BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS=null
MAIL_FROM_NAME="${APP_NAME}"
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=
PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1
MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
如果我输入不正确的密码或我的数据库和用户名,我将收到此错误:
Illuminate\Database\QueryException
SQLSTATE[HY000] [1045] Access denied for user 'database'@'localhost' (using password: NO) (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
+33 vendor frames
34 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
但是当我写入正确的数据库信息时总是 Laravel 抛出这个错误:
Illuminate\Database\QueryException
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'batch' in 'order clause' (SQL: select `migration` from `migrations` order by `batch` asc, `migration` asc)
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
667| // If an exception occurs when attempting to run a query, we'll format the error
668| // message to include the bindings with SQL, which will make this exception a
669| // lot more helpful to the developer instead of just the database's errors.
670| catch (Exception $e) {
> 671| throw new QueryException(
672| $query, $this->prepareBindings($bindings), $e
673| );
674| }
675|
• A column was not found: You might have forgotten to run your migrations. You can run your migrations using `php artisan migrate`.
https://laravel.com/docs/master/migrations#running-migrations
+27 vendor frames
28 artisan:37
Illuminate\Foundation\Console\Kernel::handle()
此错误和问题仅针对迁移系统。 在我的应用程序查询生成器中,Eloquent Laravel 运行良好。
在我的错误中它说:
• A column was not found: You might have forgotten to run your migrations. You can run your migrations using `php artisan migrate`.
但它不起作用,为什么?
解决方案
这是我的 mysql tables :
+-------------------+
| Tables_in_laravel |
+-------------------+
| migrations |
+-------------------+
migrations
table 已经存在于我的数据库中,但它是自定义迁移 table。
实际上这个 table 是由另一个框架创建的...
https://github.com/alirezaarzehgar/my-exercise-php-framework.git
我在许多网络应用程序中使用 signal@localhost mysql 用户,此操作产生了冲突。
这是我的解决方案:
首先,您应该删除当前 mysql 用户的所有 table。
在这种情况下,我只有 migrations
table :
mysql -u username -p'password' databse -e "DROP TABLE migrations"
如果你想查看你所有的迁移,你可以运行这个命令:
mysql -u username -p'password' databse -e "SHOW TABLES"
然后你可以删除所有这些table。
然后您可以 运行 您的迁移。
./artisan migrate
更改您的 'db_database' 希望您的问题能够解决
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=root
DB_PASSWORD=
删除旧的迁移table 然后重新运行 artisan migrate 看看会发生什么
首先,您应该删除当前 mysql 用户的所有 table。
在这种情况下,我只有 migrations
table :
mysql -u username -p'password' databse -e "DROP TABLE migrations"
如果您想查看所有迁移,可以运行此命令:
mysql -u username -p'password' databse -e "SHOW TABLES"
然后你可以删除所有这些 table。
然后您可以 运行 您的迁移。
./artisan migrate