Welcome Guest, Not a member yet? Register   Sign In
Cannot auto-migrate after creating DB in new Command (CI4.2)
#1

(This post was last modified: 12-18-2022, 11:07 PM by DocHojo.)

Hi there,

I'm trying to do a spark command doing all the following instruction at once:
- DROP actual DB
- CREATE DB with same name
- Migrate
- Seed
The new Command has the run method as below:

PHP Code:
    public function run(array $params) {
        // Drop table of db
        command('db:drop');
        // Migrate
        command('migrate', ['all']);
        // Seed
        command('db:seed ImportAll');
    

The db:drop command has the code below:

PHP Code:
      $name_db getenv('database.default.database');
      $this->db->query('DROP DATABASE IF EXISTS ' $name_db);
      $this->db->query('CREATE DATABASE ' $name_db); 

Problem is that the migrate command is generating an error, stating that no DB is selected.

I tried to reconnect the DB after the drop doing $this->db->connect() but no success.

The trick that works for now is to remove only the tables and not the entire DB but it is not the way I want to do it.

Any hint on how to make this working?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB