cartalyst / sentinel

A framework agnostic authentication & authorization system.
BSD 3-Clause "New" or "Revised" License
1.51k stars 238 forks source link

Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ip' in 'where clause' #541

Closed ltdev22 closed 3 years ago

ltdev22 commented 3 years ago

Your Environment

Expected behaviour

Trying to authenticate with my credentials on a php app


use Cartalyst\Sentinel\Native\Facades\Sentinel;

$data = $request->getParsedBody(); // array contains only email and password

if (!$user = Sentinel::authenticate($data)) {
    dd('Incorrect credentials');
}
dd($user);

Actual behaviour

Getting the following error on screen when I make the request

Fatal error: Uncaught PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'ip' in 'where clause' in /var/www/html/vendor/illuminate/database/Connection.php:331 Stack trace: #0 /var/www/html/vendor/illuminate/database/Connection.php(331): PDO->prepare('select * from `...') #1 /var/www/html/vendor/illuminate/database/Connection.php(664): Illuminate\Database\Connection->Illuminate\Database\{closure}('select * from `...', Array) #2 /var/www/html/vendor/illuminate/database/Connection.php(631): Illuminate\Database\Connection->runQueryCallback('select * from `...', Array, Object(Closure)) #3 /var/www/html/vendor/illuminate/database/Connection.php(339): Illuminate\Database\Connection->run('select * from `...', Array, Object(Closure)) #4 /var/www/html/vendor/illuminate/database/Query/Builder.php(2302): Illuminate\Database\Connection->select('select * from `...', Array, true) #5 /var/www/html/vendor/illuminate/database/Query/Builder.php(2290): Illuminate\Database\Query\Builder->runSelect() #6 /var/www/html/vendor/i in /var/www/html/vendor/illuminate/database/Connection.php on line 671

I'm not sure if this is related to docker, but this is the docker-compose file

mysql:
        image: mysql:5.7
        volumes:
            - dbdata:/var/lib/mysql
        ports:
            - 4306:3306
        networks:
            - appnet
        env_file:
            - ./.env

// .env file

DB_HOST=127.18.0.2
DB_DATABASE=my_db
DB_USERNAME=my_username
DB_PASSWORD=my_password

MYSQL_ROOT_PASSWORD=root
MYSQL_DATABASE="${DB_DATABASE}"
MYSQL_USER="${DB_USERNAME}"
MYSQL_PASSWORD="${DB_PASSWORD}"
suwardany commented 3 years ago

What's your database schema?

ltdev22 commented 3 years ago

id int(11) pk autoincrement first_name varchar(255) last_name varchar(255) email varchar(255) password (255) ip varchar(255) last_login_at datetime created_at datetime updated_at datetime

suwardany commented 3 years ago

ip is a column on the throttle table, i would suggest you checkout .sql files inside the schema directory of this repository.

ltdev22 commented 3 years ago

Yes I have created the tables based on schema/mysql.sql, but I was getting this error even before. So I tried to add an extra ip column in users table to test if it would fix the issue

ltdev22 commented 3 years ago

Ok, so I've re-run the schema/mysql.sql this time by copying all queries from this file (last time I created the tables manually on my gui tool). I had to change the default values for created_at and updated_at from created_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', updated_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', to created_at timestamp NOT NULL DEFAULT NOW(), updated_at timestamp NOT NULL DEFAULT NOW(), as it was complaining for invalid default value and then when I run the queries worked. Also when I tried the authenticate script I've put on my topic it worked. Not sure if this was the issue, but now seems its working fine, so I think I'm going to close this issue.

suwardany commented 3 years ago

That's why we have this file on there

https://github.com/cartalyst/sentinel/blob/5.x/schema/mysql-5.6%2B.sql