Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Adding a primary key to an existing table not working #8019

Closed
priitperna opened this issue Oct 9, 2023 · 1 comment · Fixed by #8031
Closed

Bug: Adding a primary key to an existing table not working #8019

priitperna opened this issue Oct 9, 2023 · 1 comment · Fixed by #8031
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@priitperna
Copy link

priitperna commented Oct 9, 2023

PHP Version

8.1

CodeIgniter4 Version

4.3.1

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

MySql 8

What happened?

When trying to add a primary key to an existing table, it does not work:

$this->forge->addPrimaryKey('id', 'pk_actions');
$this->forge->processIndexes('actions');

Steps to Reproduce

Create a migration to add a primary key to an existing table with the following rows:

$this->forge->addPrimaryKey('id', 'pk_actions');
$this->forge->processIndexes('actions');

Expected Output

Primary key should be added.

Anything else?

The problem seems to lie in the processIndexes() function as it only processes primary keys when a non primary key is added:

        if (! empty($this->keys)) {
            $sqls = $this->_processIndexes($this->db->DBPrefix . $table, true);

            $pk = $this->_processPrimaryKeys($table, true);

            if ($pk !== '') {
                $sqls[] = $pk;
            }
        }
@priitperna priitperna added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 9, 2023
@priitperna priitperna changed the title Bug: Bug: Adding a primary key to an existing table not working Oct 9, 2023
@kenjis
Copy link
Member

kenjis commented Oct 11, 2023

Thank you for reporting. Try #8031

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified issues on the current code behavior or pull requests that will fix them
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants