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: createTable if not exists not working #3757

Closed
crustamet opened this issue Oct 11, 2020 · 3 comments
Closed

Bug: createTable if not exists not working #3757

crustamet opened this issue Oct 11, 2020 · 3 comments
Labels
bug Verified issues on the current code behavior or pull requests that will fix them

Comments

@crustamet
Copy link
Contributor

Direction

class AddTest extends Migration
{
	public function up()
	{
		$primary_key = [
			'type'           => 'INT',
			'constraint'     => 5,
			'unsigned'       => true,
			'auto_increment' => true,
		];
		
		$title = [
			'type'           => 'VARCHAR',
			'constraint'     => '100',
		];
		
		$this->forge->addField([
			'id' => $primary_key,
			'test' => $title
		]);
		
		$this->forge->addKey('id', true);
		$this->forge->createTable('test', TRUE); 
		// HERE SECOND ARGUMENT is TRUE to create if not exists statement
	}

	public function down()
	{
		$this->forge->dropTable('test');
	}
}

Describe the bug
I still receive the error table already exists
When i check the SQL the statement "IF NOT EXISTS" does not appear in the SQL

I checked the code

CodeIgniter 4 version
Latest

Expected behavior, and steps to reproduce if appropriate
This should not give an error and instead should prepend the "IF TABLE NOT EXISTS" statement when try to create table

@crustamet crustamet added the bug Verified issues on the current code behavior or pull requests that will fix them label Oct 11, 2020
@MGatner
Copy link
Member

MGatner commented Oct 11, 2020

Please specify which database driver and, if you've only tested one and are able, please test others.

@crustamet
Copy link
Contributor Author

crustamet commented Oct 12, 2020

oh Yes sorry, i forgot about the driver, i am using MySQLi.

I tried to debug myself to check things out, what i found out

  $this->forge->createTable('test', TRUE); 

When i go to the forge class file. and go to this function and check the second param

  var_dump($ifNotExists);die();

  it gives me FALSE. I really can't find why this is happening

@crustamet
Copy link
Contributor Author

Sorry i made a mistake, everything works fine as intended.

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

No branches or pull requests

2 participants