Skip to content

Bug: php spark migrate throws wrongful CodeIgniter\Database\Exceptions\DatabaseException Unable to connect to the database #3359

@gosocial2

Description

@gosocial2

Bug Description
Impossible to perform migrations through spark (experienced in versions 4.0.2 to 4.0.4)

Although DB credentials are set in .env and/orin app/Config/Database.php and successful query results obtained through Controller classes,

php spark migrate causes CodeIgniter\Database\Exceptions\DatabaseException

Exact command line output:


CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2020-07-19 05:22:57am

Running all new migrations...
An uncaught Exception was encountered

Type:        CodeIgniter\Database\Exceptions\DatabaseException
Message:     Unable to connect to the database.
Filename:    /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/BaseConnection.php
Line Number: 425

	Backtrace:
						-646 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/BaseConnection.php::initialize
								-1548 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/BaseConnection.php::query
								-1591 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/BaseConnection.php::listTables
								-945 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/MigrationRunner.php::tableExists
								-193 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/MigrationRunner.php::ensureTable
								-128 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Commands/Database/Migrate.php::latest
								-100 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CLI/Commands.php::run
								-107 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CLI/CommandRunner.php::run
								-85 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CLI/CommandRunner.php::index
								-914 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CodeIgniter.php::_remap
								-404 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CodeIgniter.php::runController
								-312 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CodeIgniter.php::handleRequest
								-86 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CLI/Console.php::run
								-57 - /Applications/MAMP/ci4projs/deneme/spark::run

CodeIgniter 4 version
Last gotten in v4.0.4 release

Affected module(s)
spark

Expected behavior
All migrations performed successfully (without exceptions).

Steps to reproduce

  1. Open up a Terminal / command line window
  2. Change to the directory to the grand-parent level of your webserver's htdocs where htdocs will be substituted with the public directory of CI4
  3. composer create-project codeigniter4/appstarter deneme
  4. Open the project in your code editor and edit the .env file to set CI_ENVIRONMENT = development (duplicate it first from the file named 'env' if it doesn't exist - i.e. cp env .env)
  5. Perform one or both of steps 6 and 7:
  6. Enter DB credentials for MySQL in .env file (with database.default.DBDriver = MySQLi)
  7. Enter DB credentials in app/Config/Database.php
  8. Go back to the command line and run the following commands (in my example proj name is 'deneme':
    9: cd deneme
  9. php spark migrate:create AddBlog
  10. (Optional) Go back to your code editor and open the file whose name is resembles "2020_mm_dd_hhmmss_AddBlog.php" from app/Database/Migrations
  11. (Optional) Replace the contents of up() and down() methods with example from https://codeigniter.com/user_guide/dbmgmt/migration.html
  12. Go back to the command line and while still in the root directory of the CI4 project run
  13. php spark migrate
  14. Compare your Terminal output to the following output:
CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2020-07-19 05:42:10am

Running all new migrations...
An uncaught Exception was encountered

Type:        CodeIgniter\Database\Exceptions\DatabaseException
Message:     Unable to connect to the database.
Filename:    /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/BaseConnection.php
Line Number: 425

	Backtrace:
						-646 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/BaseConnection.php::initialize
								-1548 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/BaseConnection.php::query
								-1591 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/BaseConnection.php::listTables
								-945 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/MigrationRunner.php::tableExists
								-193 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Database/MigrationRunner.php::ensureTable
								-128 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/Commands/Database/Migrate.php::latest
								-100 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CLI/Commands.php::run
								-107 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CLI/CommandRunner.php::run
								-85 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CLI/CommandRunner.php::index
								-914 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CodeIgniter.php::_remap
								-404 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CodeIgniter.php::runController
								-312 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CodeIgniter.php::handleRequest
								-86 - /Applications/MAMP/ci4projs/deneme/vendor/codeigniter4/framework/system/CLI/Console.php::run
								-57 - /Applications/MAMP/ci4projs/deneme/spark::run

Context

  • OS: Experienced in macOS 10.3
  • Web server: Apache 2.x (in MAMP 5.4)
  • PHP version 7.3.7
  • MySQL 5.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions