Welcome Guest, Not a member yet? Register   Sign In
Migration Rollback does not drop table or database for SQLite3
#1

Hi,
I am using codeigniter 4.1.8. I created a migration for SQLite3 Database in which i created the database and  a table. When i run the migration, the database and table are created correctly. The problem comes when i rollback. Nothing is rolled back Appreciate help. The following is the migration script:

Code:
namespace App\Database\Migrations;

use CodeIgniter\Database\Migration;

class CreateDatadb extends Migration
{
    public function up()
    {
        $this->forge->createDatabase('mysqlite2.db');
        $this->forge->addField([
            'id' => [
                'type' => 'INT',
                'constraint' => 5,
                'unsigned' => true,
                'auto_increment' => true,
            ],
            'title' => [
                'type' => 'VARCHAR',
                'constraint' => '100',
                'unique' => true,
            ],
            'author' => [
                'type' => 'VARCHAR',
                'constraint' => 100,
                'default' => 'King of Town',
            ],
            'description' => [
                'type' => 'TEXT',
                'null' => true,
            ],
            'status' => [
                'type' => 'ENUM',
                'constraint' => ['publish', 'pending', 'draft'],
                'default' => 'pending',
            ],
        ]);
        $this->forge->addPrimaryKey('id');
        $this->forge->createTable('users');

    }

    public function down()
    {
        $this->forge->dropTable('users');
        $this->forge->dropDatabase('mysqlite2.db');

    }
}
Reply
#2

You cannot drop database in your migration files.
If it drops database, the migrations table will be lost, and you will see an error.
Reply
#3

That's because the migration has its own table in the database if you drop the database that migration table is gone.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB