Welcome Guest, Not a member yet? Register   Sign In
Migration and refresh problems
#1

(This post was last modified: 05-11-2023, 05:02 PM by sdiri.)

Hi there,

I'm sorry for any grammatical errors in my message. I hope you can help me with an issue I'm having in CodeIgniter 4.
Until now, I've been using the classic method to create databases, but I've recently started using migration and forge classes, and I'm having some problems/questions.
In my project, I have almost 10 migration files.
When I run
Code:
php spark migrate

or
Code:
php spark migrate --all
or
Code:
php spark migrate:refresh



, everything works fine except for one migration file. It gives me an error message saying that the
usersexperiences
table already exists, which is not true .

I have deleted this table from the database and tried again, but I still get the same error message in my terminal.
I have also deleted both, the table and the field in my migration table in the database that indicate the class namespace and tried again, but I'm still getting the same error message.
All the other migrations pass except for this one "he create the table but always with table exist error!" .
I added true as agrs in create createTable method and dropTable method but still the same error.
unfortunatly this boolean argument not longer supported and deprecated.
this my migration class :
PHP Code:
<?php

namespace App\Database\Migrations;

use 
CodeIgniter\Database\Migration;

class 
UsersExperiences extends Migration
{
    public function up()
    {
        log_message('info''Up function called ' time());
        $this->forge->addField([
            'id'              => ['type' => 'INT''unsigned' => true'auto_increment' => true],
            'user_id'          => ['type' => 'INT''unsigned' => true],
            'organization_id'  => ['type' => 'INT''null' => true],
            'skill_id'        => ['type' => 'INT''null' => true],
            'title'            => ['type' => 'CHAR''constraint' => '32''null' => false],
            'description'      => ['type' => 'VARCHAR''constraint' => '255''null' => true],
            'sdate'            => ['type' => 'DATE''null' => true],
            'edate'            => ['type' => 'DATE''null' => true],
            'is_inetrnational' => ['type' => 'TINYINT''constraint' => 1],
            'lang_id'          => ['type' => 'TINYINT''null' => true],
            'active'          => ['type' => 'TINYINT''constraint' => '1''null' => false],

            'created_by' => ['type' => 'INT''null' => false],
            'deleted_by' => ['type' => 'INT''null' => true],
            'updated_by' => ['type' => 'INT''null' => true],

            'created_at' => ['type' => 'DATETIME''null' => false],
            'updated_at' => ['type' => 'DATETIME''null' => true],
            'deleted_at' => ['type' => 'DATETIME''null' => true],
        ]);

        $this->forge->addKey('id'true);
        $this->forge->createTable('usersexperiences');
    }

    public function down()
    {
        log_message('info''Down function called ' time());
        $this->forge->dropTable('usersexperiences');
    }

The error:
[Image: Capture-d-cran-2023-05-12-003338.png]


Question:
Why do I get an error saying the table does not exist when I changed the table name from
usersexperiences to usersexp ?
Additional Questions:
How do I add new fields to a table using migrations?
Can migrations help me keep versions of the database, tables, and fields and rollback when needed?
Any help you can provide would be greatly appreciated.


Thank you.
Reply
#2

> How do I add new fields to a table using migrations?

See https://codeigniter4.github.io/CodeIgnit...to-a-table
Reply
#3

(This post was last modified: 05-12-2023, 01:53 AM by luckmoshy.)

Because the batch number is still presented in migration table you should do by following batch number
PHP Code:
php spark migrate:rollback 

as hrere https://codeigniter4.github.io/CodeIgnit...n#rollback

find your batch https://codeigniter4.github.io/CodeIgnit...ion#status
Codeigniter First, Codeigniter Then You!!
yekrinaDigitals

Reply




Theme © iAndrew 2016 - Forum software by © MyBB