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

Fixture problems #12002

Closed
RSalo opened this issue Jul 21, 2016 · 8 comments
Closed

Fixture problems #12002

RSalo opened this issue Jul 21, 2016 · 8 comments
Labels
status:need more info status:to be verified Needs to be reproduced and validated.

Comments

@RSalo
Copy link

RSalo commented Jul 21, 2016

What steps will reproduce the problem?

Load fixture and then clear it up(unload) and then again try to load it.

What is the expected result?

Reset table with refreshing PK.

What do you get instead?

Instead i getting an error:

C:\Users\RSalo\PhpstormProjects\shelter-app>php yii fixture/load *
Fixtures namespace is:
tests\unit\fixtures

Global fixtures will be used:

    1. yii\test\InitDb

Fixtures below will be loaded:

    1. User

Be aware that:
Applying leads to purging of certain data in the database!

Load above fixtures? (yes|no) [no]:yes
Exception 'yii\db\IntegrityException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '3' for key 'PRIMARY'
The SQL being executed was: INSERT INTO user (id, email, password, firstName, lastName, nickname, birthday) VALUES (3, '[email protected]', '$2y$13$vFgN7K6qEZ85KK9kjYolYuY/zyqSZFSBRi0EslahhD6ia1lSVIQNe', 'Roman', 'Salo', 'test2', '1990-035-26')'

in C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\db\Schema.php:633

Error Info:
Array
(
[0] => 23000
[1] => 1062
[2] => Duplicate entry '3' for key 'PRIMARY'
)

Stack trace:

0 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\db\Command.php(854): yii\db\Schema->convertException(Object(PDOException), 'INSERT INTO `us...')

1 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\db\Schema.php(451): yii\db\Command->execute()

2 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\test\ActiveFixture.php(80): yii\db\Schema->insert('user', Array)

3 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\test\FixtureTrait.php(93): yii\test\ActiveFixture->load()

4 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\console\controllers\FixtureController.php(157): yii\console\controllers\FixtureController->loadFixtures(Array)

5 [internal function]: yii\console\controllers\FixtureController->actionLoad(Array)

6 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\base\InlineAction.php(55): call_user_func_array(Array, Array)

7 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\base\Controller.php(154): yii\base\InlineAction->runWithParams(Array)

8 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\console\Controller.php(119): yii\base\Controller->runAction('load', Array)

9 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\base\Module.php(454): yii\console\Controller->runAction('load', Array)

10 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\console\Application.php(180): yii\base\Module->runAction('fixture/load', Array)

11 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\console\Application.php(147): yii\console\Application->runAction('fixture/load', Array)

12 C:\Users\RSalo\PhpstormProjects\shelter-app\vendor\yiisoft\yii2\base\Application.php(375): yii\console\Application->handleRequest(Object(yii\console\Request))

13 C:\Users\RSalo\PhpstormProjects\shelter-app\yii(13): yii\base\Application->run()

14 {main}

Additional info

Q A
Yii version 2.0.9
PHP version 5.6
Operating system Windows 10.1
@samdark
Copy link
Member

samdark commented Jul 22, 2016

Looks like cleanup was not performed.

@samdark samdark added the status:to be verified Needs to be reproduced and validated. label Jul 22, 2016
@samdark samdark added this to the 2.0.x milestone Jul 22, 2016
@samdark
Copy link
Member

samdark commented Jul 22, 2016

Any idea why?

@RSalo
Copy link
Author

RSalo commented Jul 22, 2016

I think it's happened due PK in the table. Just to deleting values is not help. We need do something like this on the table
TRUNCATE TABLE table_name;

@samdark
Copy link
Member

samdark commented Jul 22, 2016

Duplicate entry '3' for key 'PRIMARY' means there's a row with PK = 3 in the table and we're trying to insert another row with PK = 3.

Could be because:

  1. Cleanup wasn't performed properly.
  2. PK is specified explicitly for some entries in fixtures.

@samdark
Copy link
Member

samdark commented Jul 22, 2016

Check what's in database right after the error.

@RSalo
Copy link
Author

RSalo commented Jul 22, 2016

Cleanup was performed properly, because table became is empty... except PK...

@samdark
Copy link
Member

samdark commented Jul 22, 2016

What do you mean by "except PK"? Do you mean it starts not with 1 but with something else when auto-incrementing? If yes then there should be PK = 3 defined somewhere explicitly. I guess your culprit is in user fixture. Remove explicit ID and it should be fine.

@samdark samdark closed this as completed Jul 22, 2016
@RSalo
Copy link
Author

RSalo commented Jul 22, 2016

You're right, it was explicit ID in fixture... Thank you!

@cebe cebe removed this from the 2.0.x milestone Aug 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:need more info status:to be verified Needs to be reproduced and validated.
Projects
None yet
Development

No branches or pull requests

3 participants