I started a new project using laravel^6.2 using the laravel new myapp command.
I edit then my .env file to connect to my local database:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=8082
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=root
I decide then to migrate the default database structure from laravel. when I say default structure I'm talking about the users migration which is already created from the beginning present in the 2014_10_12_000000_create_users_table.php file:
<?php
// *** This has been generated from `laravel new myapp` ***
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::dropIfExists('users');
}
}
So I run the php artisan migrate command and then something unexpected happens. Indeed, after that the terminal doesn't do anything as if it was on break. I'm thinking maybe the command takes a while to execute but after several tries that lasted about ten minutes, nothing happens.
So I decide to consult the logs but absolutely nothing's written down, it's totally empty.
So I'm trying to execute php artisan cache:clear and start over but the result is the same: No error messages and nothing happens.
I know the question has been asked here before, but no answer really came up.
Has somebody an idea what I have missed ?
Try changing the port to the default MySQL port 3306.
Port 8082 as you have it sounds unusual, unless you have set that port in your MySQL server.
From your comment:
there are multiple "localhost" servers running on your machine:
your localhost web server, port 80 usually (in your case 8082)
your localhost mysql server, port 3306 usually.
There might also be a localhost postgres server, running (default) at port 5432, a localhost redis server at port 6379 or many others.
Related
I'm currently working with Laravel and came across a strange issue, though I could not find any answer to it.
When I install Laravel (Jetstream) on Docker with NGINX (Latest), PHP-FPM (PHP 8) and MariaDB 10.5, everything works as expected and I can run all migrations.
As soon as I switch to MariaDB 10.6 I get
SQLSTATE[HY000] [2002] Connection refused (SQL: alter table `team_invitations` add unique `team_invitations_team_id_email_unique`(`team_id`, `email`))
Strangely all table creations work as expected.
This is the migration part where it comes from:
Schema::create('team_invitations', function (Blueprint $table) {
$table->id();
$table->foreignId('team_id')->constrained()->cascadeOnDelete();
$table->string('email');
$table->string('role')->nullable();
$table->timestamps();
$table->unique(['team_id', 'email']);
});
Does anyone have an idea where this comes from/what the solution could be?
The stack trace shows me correct network / database settings.
Also running the query manually works as expected.
I recently just setup laravel homestead on my development machine and everything has been smooth and I love it. However, I am trying to add some columns to an existing table using migration but when running the php artisan migrate command doesn't complete. It seems to start but never completes even after leaving it for more than 10mins.
Here's my migration
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddColumnsToTransfersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('transfers', function (Blueprint $table) {
$table->integer('otp')->after('bank_code')->nullable();
$table->boolean('authorized')->after('otp')->nullable()->default('0');
$table->string('recipient_code')->after('authorized')->nullable();
$table->boolean('approval_required')->after('recipient_code')->nullable()->default('0');
$table->unsignedBigInteger('approved_by')->after('approval_required')->nullable();
$table->foreign('approved_by')->references('id')->on('users')->onDelete('set null');
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::table('transfers', function (Blueprint $table) {
//
});
}
}
And this is the result of the command php artisan migrate
I know db connection is fine as I am able to login and pull data from the database inside the application. I was able to generate the migration file using php artisan make:migration command so I have no idea why is seems to be stuck when I try to run the actual migration.
It seems there was an issue with mysql service. So I stopped the service by running sudo service mysql restart then ran php artisan migrate, and the table was successfully migrated. Problem solved.
I fairly new to laravel and a beginner in monogo db. I have been trying to connect mongodb cluster of mongodb atlas in my laravel project.
But when I am trying to migrate the laravel migration file it is showing error saying mysql error even after I changed the default connection to mongodb.
Can anyone please tell me how can I fix this issue and migrate the current project to mongodb?
PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=homestead", "homestead", "secret", [])
1 PDOException::("SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
")
C:\Users\admin\Desktop\test\test\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php : 68
C:\Users\admin\Desktop\test\test\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php : 68
Since laravel doesnt allow mongodb out of the box, so I am using a mongodb package https://github.com/jenssegers/laravel-mongodb
And I also would like to mention that I have monngodb installed in my php as per the documentation. I can see the confirmation of mongodb on phpinfo() page. My settings are as follows:
My .env
DB_CONNECTION="mongodb"
DB_MONGO_PORT=27017
DB_MONGO_DATABASE=test
DB_MONGO_DSN="mongodb+srv://<USERNAME>:<PASSWORD>#cluster0-
***.mongodb.net/test"
My config/database.php
'default' => env('DB_CONNECTION', 'mongodb'),
'mongodb' => [
'driver' => 'mongodb',
'dsn' => env('DB_MONGO_DSN'),
'database' => env('DB_MONGO_DATABASE'),
],
My user migration file
use Illuminate\Support\Facades\Schema;
//use Illuminate\Database\Schema\Blueprint;
use Jenssegers\Mongodb\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
protected $connection = 'mongodb';
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('users');
}
}
I'm not sure why it's not working with the default connection set to mongodb, but I've ran into this problem before. The issue I was having is that the connection property in the migration is useless. I had to do the following;
Schema::connection($this->connection)->create('collections', function (Blueprint $table) {
$table->increments('id');
$table->index('slug');
$table->index('world_id');
$table->unique(['world_id', 'slug']);
$table->timestamps();
});
Schema::connection('mongodb') should work for you.
put DB_CONNECTION=mongodb on your .ENV file.
Also remove quotes from MOGN0_DSN and make sure to call php artisan config:cache to dump the autoloaded configuration file
Try this package.
It's easy to use.
https://packagist.org/packages/jenssegers/mongodb
Try .env file as
DB_CONNECTION=mongodb
without qoutes
I tried to implement the default auth login system in laravel
php artisan make:migration create_users_table
Created Migration: 2016_03_10_115611_create_users_table
On running the above command only migration file is created and not the tables are created.
Also i have tried to reinstall composer but it didn't work
//In 2016_03_10_115611_create_users_table file
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('users');
}
}
on running
php artisan migrate
it took a few amounts of time and returned
[ErrorException]PDO::__construct(): MySQL server has gone away
Thanks to everyone i have not configured the .env file properly so that it doesn't work
What's your MySQL version?
Or you not yet modify .env
Try SQLite and change settings database to sqlite. I think this problem on php extension.
First you have run this command to install migration
php artisan migrate:install
Note :- if you look at database/migrations there will be already two migrations files
2014_10_12_000000_create_users_table.php
2014_10_12_100000_create_password_resets_table.php
php artisan migrate
I'm getting an error on my deployed application:
Base table or view not found: 1146 Table 'ebdb.users' doesn't exist
This leads me to believe my php artisan migrate command isn't working, and the users table isn't being created.
This is one of my config files (in my .elasticbeanstalk folder)
container_commands:
00testCommand:
command: "echo test"
01migrateSeed:
command: "php artisan migrate --force"
02seed:
command: "php artisan db:seed --force"
This is my create users migration file:
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->string('referral_id')->unique();
$table->string('referred_by')->nullable()->default(null);
$table->string('password', 60);
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::drop('users');
}
}
Am I missing something obvious? Is this error not related to my migration? I'd like to know if these commands are even being run, but can't find them in the Elastic Beanstalk environment log.
Any help appreciated, thanks.
move the config file to the .ebextensions folder. it does not belong to the .elasticbeanstalk one