Laravel 5 database issue

Asked
Active3 hr before
Viewed126 times

7 Answers

database
90%

Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers , Stack Overflow help chat , Run this two command for solving SQLSTATE[HY000] [1049] Unknown database............ – Kabir Hossain Mar 19 '16 at 10:39 , Stack Overflow Public questions & answers

Change the following attribute from database.php

'mysql' => [
   'driver' => 'mysql',
   'host' => env('DB_HOST', 'localhost'),
   'database' => env('DB_DATABASE', 'forge'),
   'username' => env('DB_USERNAME', 'forge'),
   'password' => env('DB_PASSWORD', ''),
   'charset' => 'utf8',
   'collation' => 'utf8_unicode_ci',
   'prefix' => '',
   'strict' => false,
]

to

 'mysql' => [
    'driver' => 'mysql',
    'host' => 'localhost',
    'database' => 'laravel',
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix' => '',
    'strict' => false,
 ],

This must work well then run the following command:

php artisan migrate: install
load more v
88%

Read / Write Connections,Accessing Connections,Once you have configured your database connection, you may run queries using the DB facade.,Sometimes you may wish to use one database connection for SELECT statements, and another for INSERT, UPDATE, and DELETE statements. Laravel makes this a breeze, and the proper connections will always be used whether you are using raw queries, the query builder, or the Eloquent ORM.

To see how read / write connections should be configured, let's look at this example:

'mysql' => [
   'read' => [
      'host' => '192.168.1.1',
   ],
   'write' => [
      'host' => '196.168.1.2'
   ],
   'driver' => 'mysql',
   'database' => 'database',
   'username' => 'root',
   'password' => '',
   'charset' => 'utf8',
   'collation' => 'utf8_unicode_ci',
   'prefix' => '',
],
load more v
72%

From there your application will run as expected.,So what are the most common errors that people see when using Laravel for the first time? Let's take a look.,To generate an application key, simply run the following;,You haven't run the migration(s)

To generate an application key, simply run the following;

php artisan key: generate

Open your AppServiceProvider.php file, and add the following;

  use Illuminate\ Support\ Facades\ Schema;

  public
  function boot() {
     Schema::defaultStringLength(191);
  }
load more v
65%

Laravel 5.4 made a change to the default database character set, and it’s now utf8mb4 which includes support for storing emojis. This only affects new applications and as long as you are running MySQL v5.7.7 and higher you do not need to do anything.,As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:,After that everything should work as normal. If you enjoyed this post be sure and join the weekly Laravel newsletter and never miss out on new releases, framework tips, and new tutorials.,For those running MariaDB or older versions of MySQL you may hit this error when trying to run migrations:

As outlined in the Migrations guide to fix this all you have to do is edit your AppServiceProvider.php file and inside the boot method set a default string length:

1 use Illuminate\ Support\ Facades\ Schema;
23 public
function boot() 4 {
   5 Schema::defaultStringLength(191);
   6
}
75%

It happens mainly due to incorrect database details in Laravel database configuration file, bad user privileges, etc.,In short, Laravel integrates databases easily. However, incorrect database details, insufficient user privileges, etc can result in Laravel database connection error. Today, we saw how our Support Engineers fixed this error.,4. It’s time to make changes in .env configuration file. Here, we need to add the database details.,So, we corrected the database details in config/database.php and .env file.

So, we edit the following data in the .env file according to the database settings.

DB_CONNECTION = mysql
DB_HOST = 180.0 .0 .1
DB_PORT = 4008
DB_DATABASE = name
DB_USERNAME = root
DB_PASSWORD =
load more v
40%

I've installed laravel 5 successfully by using this command:,I even verified the version of installed laravel by using php artisan -V command. The output was,But I've neither used laravel homestead for installng laravel 5 in my system nor used vagrant to set up laravel homestead. And it tells me like this:,I am working on a #code# clause eloquent model. I want to find the collection with the size of an array field having size values greater than, less than, betwee...

I've installed laravel 5 successfully by using this command:

composer create - project laravel / laravel test - laravel - 5 - project dev - develop--prefer - dist
load more v
22%

Database Driver & Version: MySQL 5.7.21,SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes,Laravel Version: 5.6.26,Illuminate\Database\QueryException

'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
load more v

Other "database-undefined" queries related to "Laravel 5 database issue"