skip to Main Content
[SOLVED]

i new to Laravel and PHP.

i tried to migrate my own migrations but i can’t.

this my laravel and php information:

my php info

  • 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

my OS info

  • uname: Linux ali 5.4.105-1-MANJARO #1 SMP PREEMPT 2021 x86_64 GNU/Linux

when i run command ./artisan migrate or php artisan migrate Laravel throws this error:

   IlluminateDatabaseQueryException 

  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
      IlluminateFoundationConsoleKernel::handle()

it’s always happens on my system regardless of my migration files.
it means that if i migrate my app when i haven’t even one migration file, this error will appear.

for example i create a project with this steps:

composer create-project laravel/laravel mig "8.x"

this problem tested on 8.x, 7.x, 6.x versions.

cd mig

change my .env file and set below variables :

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME="my database"
DB_PASSWORD="my pasword"

this my .env file :

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}"

if i write incorrect password or my database and username i will get this error :

   IlluminateDatabaseQueryException 

  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
      IlluminateFoundationConsoleKernel::handle()

but when i write correct database info always Laravel throws this error:


   IlluminateDatabaseQueryException 

  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
      IlluminateFoundationConsoleKernel::handle()

this error and problem is just for migrations system.
in my app Query Builder and Eloquent Laravel works well.

in my error it say that :

• A column was not found: You might have forgotten to run your migrations. You can run your migrations using `php artisan migrate`.

but it’s not work, why ?

SOLUTION

this my mysql tables :

+-------------------+
| Tables_in_laravel |
+-------------------+
| migrations        |
+-------------------+

the migrations table already exists in my database, but it’s a custom migration table.
actually this table created by another frameworks …
https://github.com/alirezaarzehgar/my-exercise-php-framework.git

i use signal@localhost mysql user in many web app and this action made a conflict.

this my solution :

first of all you should delete all tables on your current mysql user.
in this case i just have migrations table :

mysql -u username -p'password' databse -e "DROP TABLE migrations"

if you want see all of your migrations you can run this command:

mysql -u username -p'password' databse -e "SHOW TABLES"

and then you can delete all of this tables.

then you can run your migrations.
./artisan migrate

3

Answers


  1. Chosen as BEST ANSWER

    first of all you should delete all tables on your current mysql user. in this case i just have migrations table :

    mysql -u username -p'password' databse -e "DROP TABLE migrations"

    if you want see all of your migrations you can run this command:

    mysql -u username -p'password' databse -e "SHOW TABLES"

    and then you can delete all of this tables.

    then you can run your migrations. ./artisan migrate


  2. change your ‘db_database’ hopefully your problem will resolve

    DB_CONNECTION=mysql
    DB_HOST=127.0.0.1
    DB_PORT=3306
    DB_DATABASE=your_database_name
    DB_USERNAME=root
    DB_PASSWORD=
    
    Login or Signup to reply.
  3. Delete the old migration table then re-run artisan migrate and see what happenes

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search