Can't migrate in laravel - php

I made a small project in laravel using MAMP, and everything works fine.
Now I'd like to put the project online.
I copied the project with FTP and changed the database.php file.
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'private.be.mysql'),
'database' => env('DB_DATABASE', 'private_be'),
'username' => env('DB_USERNAME', 'private_be'),
'password' => env('DB_PASSWORD', 'private'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
The installation works fine when visiting the website, but when visiting a page that uses a connection to the database I get following error.
SQLSTATE[42S02]: Base table or view not found:
1146 Table 'private_be.users' doesn't exist (SQL: select * from `users`)
So I found out I had forgot to migrate my project. But when typing the command 'php artisan migrate' I get the following error in terminal.
[ErrorException]
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename
nor servname provided, or not known
At first I thought maybe my settings for 'mysql' were incorrect, but I'm sure they are.
My .env file looks like this
APP_ENV=local
APP_DEBUG=true
APP_KEY=***
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
Anybody who can help me fixing the migrate error?

Sounds like you didn't run your database migrations.
After you moved the files over, did you SSH into the server and go to your project directory and run the command
php artisan migrate
Running the above command will create all database tables you created migrations for. If you already have some data that needs to be rolled back first then rebuilt you can use:
php artisan migrate:refresh

Related

SQLSTATE[28000] [1045] Access denied for user [duplicate]

I just installed laravel and made a migration. But when i try to run it i get this error:
[PDOException]
SQLSTATE[28000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
Can anyone tell me what is wrong? I think the Database.php file looks different than normal. Is this something new in the new Laravel?
My Database config:
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'LaraBlog'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'root'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
Hope someone can help me :)
I tried to make changes to database.php file present within config folder it looks something like this
'default' => 'mysql',
....
...
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'sample'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
I am not using any VM, I am using my local machine, with the database user as root and password a null.
I have also changed my .env file and it looks something like this:
APP_ENV=local
APP_DEBUG=true
APP_KEY=zLzPMzs5W4FNNuguTmbG8M0iFqhIVnsP
DB_HOST=localhost
DB_DATABASE=sample
DB_USERNAME=root
DB_PASSWORD=null
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
Even after doing all the changes when I try to register using the registration form that is shipped with laravel, I try to add a user to my database I get the following error
After doing all the changes I cleared the cache and loaded it again and it seems to work for me now!
if any one is also facing the same issue just run the following commands
php artisan cache:clear
php artisan config:cache
I figured it out :) Had to chance the .env file :)
Is there any changes in the schemaes?
Shouldn't this work:
public function up()
{
// Create table with columns
Schema::create('users', function($table) {
$table->increments('id');
$table->string('username');
$table->string(Hash::make('password'));
$table->string('firstname');
$table->string('lastname');
$table->string('email')
$table->string('role');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
// Insert table to database
Schema::drop('users');
}
Try to check out the ".env" file in your root directory. These values are taken first. Yours are just the defaults if there are none given in the .env file.
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=Your_Database_Name
DB_USERNAME=Your_UserName
DB_PASSWORD=Your_Password
Make changes in the database.php file in **config > local >database.php
rather than change config > database.php file.
hope it will work ;)
practically when you are using localhost server like xampp, you create the database manually "homestead", such errors are due to missing database arguments. 100% percent working test it and see
hit your cmd and type in:
create database homestead;
i got the same issue after creating laravel project. The authentication command run successfully.
php artisan make:auth
But when i try to register or login i got the same error. I run the following command
php artisan config:clear
then stopped laravel application and also my server. after restarting my laravel app and server everything was ok.
Tried all the solutions here but no work for me
This Worked on the first try:
If you are using the PHP's default web server (eg. php artisan serve) you need to restart your server after changing your .env file values.
I found this solution from here laravel.io (Read the solution of Byjml)

Laravel 5.3 - PHP Artisan Migration

I'm new to Laravel and just started with Laravel 5.3. While watching my tutorials and on my way to the Models video I encountered a problem with my "connection".
[Illuminate\Database\QueryException]
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using pas
sword: YES) (SQL: select * from information_schema.tables where table_schem
a = testing and table_name = migrations)
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'root'#'localhost' (using pas
sword: YES)
Here's my database.php: (I tried configuring it before where the values are the same with my .env file but it still didn't work. I'm posting my current database.php file to get more insight/knowledge about configuration.)
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
And here's my .env file:
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3307
DB_DATABASE=testing
DB_USERNAME=root
DB_PASSWORD=password
I don't use homestead and running only on my local server. I'm also using xampp on Windows 7.
Change you .env file like this --
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testing
DB_USERNAME=root
DB_PASSWORD=
leave the password empty. Then try again.
Still error? then check the following --
If using xampp, wampp or any, dont forget to run mysql and apache.
A database with name 'testing' is created in phpmyadmin or any other
It looks like your username or password is not correct.
Are you sure you have .env.example renamed to .env?
This video may be helpful if you are trying to find information regarding artisan command https://www.youtube.com/watch?v=ix6CQ3rh8WY
There are several reasons for this error,
I hope this will save your time:
1- Confirm that the mysql and apache is running.
2- Setup (create) your database before the first deployment.
3- if you use vagrant, use vagrant IP instead of 127.0.0.1
4- Install latest version of PDO.

php artisan migrate isn't working

When I try to connect to my database i get this error
[PDOException]
SQLSTATE[HY000] [1045] Access denied for user 'loom'#'localhost' (using password: YES)
all my credentials are correct and when i change things up i get this error :
[PDOException]
SQLSTATE[HY000] [1049] Unknown database 'loomcoding'
Can anyone help me sort this out please
my .env file
APP_ENV=local
APP_DEBUG=true
APP_KEY=xxxx
DB_HOST=localhost
DB_DATABASE=cl20-loom
DB_USERNAME=loom
DB_PASSWORD=xxxx
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
my database.php file :
'mysql' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'cl-loom',
'username' => 'loom',
'password' => '••••',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
I got this error last time create a database on phpmyadmin and change only the .env file to match with you phpmyadmin details and it will work.
It can be because the mysql service is not running or it isn't on the port 3306, in the last case you may specify the port where the mysql service is running as a attribute port of the mysql object in database.php file
If you are using mysql you have to create the database manually in phpMyAdmin or whatever software you are using for mysql.
And no need to change the whole database.php if you configure the .env file. Just change this line 'default' => env('DB_CONNECTION', 'mysql'), in database.php
Below code is not tested
Instead, you can add DB_CONNECTION=mysql this line in .env

laravel cant connect to mysql database on VM LAMP

hey guys im trying to learn laravel and im following the tutorail but i cant seem to connect to my database via VM running LAMP. I've looked thru every single post and nothing is still working
when i go run the command php artisan migrate i get the following error
[PDOException]
SQLSTATE[HY000] [2003] Can't connect to MySQL server on '10.0.1.22' (111)
i even followed this post and got the following error
[PDOException]
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/opt/lampp/var/mysql/mysql.sock' (2)
my laravel app is running on port 8000 but my phpmyadmin is at 10.0.1.22/phpmyadmin im not sure if that could be the issue, im still a beginner so my debugging solutions are limited.
Here are my database.php file and my .envi file
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '10.0.1.22'),
'database' => env('DB_DATABASE', 'task'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', 'test'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
and my .envi file
APP_ENV=local
APP_DEBUG=true
APP_KEY=HBzhX830sIrNbZ2hdB23DGAuGa4mj4IL
DB_HOST=10.0.1.22
DB_DATABASE=task
DB_USERNAME=root
DB_PASSWORD=test
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
thanks for all the help
Change the DB_HOST to 127.0.0.1
10.0.1.22 is the external address to your VM machine from your computer.
Since Apache/PHP and MySQL are running on the same machine, there's no reason connect them with the external address but rather with the internal (127.0.0.1).
When you create a user in MySQL you can set what IP'addresses it should accept connections from and as default, in most cases, the root user is usually set to only listen to internal calls (127.0.0.1).
Change your
DB_HOST=10.0.1.22
to
DB_HOST = 127.0.0.1
Because Loaclhost define on this port. Simply it means 127.0.0.1 == localhost
$cfg['Servers'][$i]['host']

connecting to database issue in laravel 5.1

I am new to laravel and while trying to connect to database in localhost using xammp iam getting an error that
SQLSTATE[HY000] [1045] Access denied for user 'homestead'#'localhost' (using password: YES)
my connection code is that
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'hindutemples'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
but 'hindutemples' database exists i dnt know why it is trying to connect with homestead
Any help appreciated.
rename .env.example to .env. Then set appropriate values in .env files. It should work.
UPDATE
Laravel 5 stores settings in .env file. Laravel 5 comes with default .env.example file in a root folder. If you can not find it in project root it may have been hidden.
You need to rename .env.example or create new .env file inside project root and put app settings in it like given below,
APP_ENV=local
APP_DEBUG=true
APP_KEY=0SewSBZ47SfA4vRV6o8BeW74PMFwPpoX
DB_HOST=localhost
DB_DATABASE=hindutemples
DB_USERNAME=root
DB_PASSWORD=
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
env() returns values from .env files. if it could not find setting in .env file it returns false or if supplied default e.g. env('DB_USERNAME', 'homestead') it will return default value. in your case it can not find .env setting so it is returning homestead as a username and hence error.
Read More

Categories