Welcome Guest, Not a member yet? Register   Sign In
CodeIniter 4 plus Myth/Auth throws error when runnung Migrations via php spark migrat
#1

I have discovered some weird bevavior, I have that one CI4 project i am working on since a couple of weeks. everything is working just fine, but until now i have just been working withe the project on my local machine. When i wanted to ron the project on my Laptop in ran into an error when i tried to run the migrations with php spark migrate -all

 
Code:
CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2020-07-20 06:16:02am
   
   
   
    Running all new migrations...
   
    An uncaught Exception was encountered
   
   
   
    Type:        CodeIgniter\Database\Exceptions\DatabaseException
   
    Message:    Unable to connect to the database.
   
    Filename:    /opt/lampp/htdocs/sms/vendor/codeigniter4/framework/system/Database/BaseConnection.php
   
    Line Number: 425


The project includes Myth/auth, so i tried just to run "my" migration with php spark migrate . That just worked fine, no problem at all, the tables are there, no eroors. Just for fun, i moved my Math/auth migrations from the vendor folder to the "normal" Database/Migrations folder and was able to migrate them that way.

Thats very weird, especally since everything is working just fine on the PC I have been using before. There I am able to run the migrations using php spark migrate -all without any errors, when is set up a fresh MySQL/MariahDB database. But somehow only there.


I was able to reprocude the error on my laptop on my Manjaro partition, my Windows 10 partion an on my iMac.
So if you want to reproduce the error  do the following:

1.
Code:
composer create-project codeigniter4/appstarter whatever

2. renaame the `env` to .`env`
3. set `CI_ENVIRONMENT = development` and obviously uncomment that line
4. configure and uncomment your database setting in the .env
5. create a sample migration like the one from the docs using
Code:
> php spark migrate:create AddBlog

6. add the following content  to the new migration and save the file:
   
PHP Code:
<?php namespace App\Database\Migrations;
   
    
use CodeIgniter\Database\Migration;
   
    
class AddBlog extends Migration
    
{
   
            
public function up()
            {
                    $this->forge->addField([
                            'blog_id'          => [
                                    'type'          => 'INT',
                                    'constraint'    => 5,
                                    'unsigned'      => true,
                                    'auto_increment' => true,
                            ],
                            'blog_title'      => [
                                    'type'          => 'VARCHAR',
                                    'constraint'    => '100',
                            ],
                            'blog_description' => [
                                    'type'          => 'TEXT',
                                    'null'          => true,
                            ],
                    ]);
                    $this->forge->addKey('blog_id'true);
                    $this->forge->createTable('blog');
            }
   
            
public function down()
            {
                    $this->forge->dropTable('blog');
            }
    


7. run
Code:
> composer require myth/auth


8. Edit app/Config/Email.php and verify that a fromName and fromEmail are set as that is used when sending emails for password reset, etc.

9. Edit app/Config/Validation.php and add the following value to the ruleSets array: \Myth\Auth\Authentication\Passwords\ValidationRules::class

10. Ensure your database is setup correctly, then run the Auth migrations:
Code:
php spark migrate -all


11. As a result you will also have the above error. I was not able to
    get around that error, except for the system in was working with at
    first.

12. If you just use 
Code:
php spark migrate
it will migrate the sample migartion without any errors.


I was NOT able NOT to reproduce the error on three different machines, on the other hand, i was not able to reproduce the error in the PC i used first during the last couple of weeks.
Reply
#2

(This post was last modified: 08-25-2020, 10:50 AM by InsiteFX.)

I just ran it and it works fine.

Code:
php spark migrate -all

If you change your folder structure then you will need to edit the spark file and change public to your path.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

Seems odd indeed. In your workflow above, does the issue still occur if you don’t do the additional configuration steps (8 & 9)? How about if there is no migration in your App? Have you tried it against the latest code on the developer branch (try running “builds” after step 1, or some Windows equivalent)?
Reply
#4

Same happened to me when using MAMP Pro for Mac.

I had resolved the issue by changing “localhost” to 127.0.0.1 in the .env file.

CodeIgniter Wizard (CRUD code generator for Mac) instantly scaffolds Bootstrap-based web applications with an administrative interface (admin templates include Bootstrap5)

Reply




Theme © iAndrew 2016 - Forum software by © MyBB