Fixture loaded successfully, but no data entered


(Peterbrinkhuis) #1

Remark: I’ve also posted my questions at Stackoverflow (but I am not allowed to add a link to this post), but this forum probably has more Yii users ;)

I have three issues when trying to load and unload Yii2 fixtures without using Codeception:

[list=1]

[*]Unloading a fixture would not do anything

[*]Loading a fixture with dependencies would not load anything

[*]I can’t find a log file to check for issues with the fixtures

[/list]

In the first two cases, my terminal window insists that everything worked well. The first issue was fixed by defining the unload function because it is still being discussed as Yii issue #5442 on Github (again, no links allowed). So every fixture will have the following added:


public function unload(){

    parent::unload();

    $this->resetTable();

}

Loading fixtures with dependencies works when the following is added to each fixture:


public function beforeLoad() {

        parent::beforeLoad();

        $this->db->createCommand()->setSql('SET FOREIGN_KEY_CHECKS = 0')->execute();

    }


    public function afterLoad() {

        parent::afterLoad();

        $this->db->createCommand()->setSql('SET FOREIGN_KEY_CHECKS = 1')->execute();

    }

I am now able to load a fixture with a dependency, but only the data of the dependency actually ends up in the database. Now I think there is something wrong with my data file. Is there a log file that I can check for issues?


(Peterbrinkhuis) #2

I have made some progress. I installed a tool for remote MySQL management and there I am able to add an entry in the UserLibraries table. I also enabled MySQL logging and found the following lines after a UserLibrary fixture load:

  • Disable foreign key checks

  • User table reset

  • Alter table user auto_increment=1

  • User 1 added

  • User 2 added

  • UserLibraries table reset

  • Alter table userlibraries auto_increment=1

  • Enable foreign key checks

So the only thing that isn’t being done is inserting the data of the UserLibraries.


(Peterbrinkhuis) #3

Still no real progress:

  • I can add data to the user table via a fixture

  • I can add data to the user_libraries table via CRUD

  • I can add data to the user_libraries table via HeidiSQL

  • I can not add data to the user_libraries table via a fixture

  • I can not add data to any other table via a fixture

I’m now looking at the difference between the table that I can add content to via a fixture (user), and the one that I can’t add entries to (user_libraries). In the migration of the user table, it says the following:


$tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

I haven’t added this to all other tables, could that be an issue? According to HeidiSQL, all other tables already use the InnoDB engine. I’ve manually set the option for the user table and user_libraries table so they are identical, but no cigar.


(Peterbrinkhuis) #4

Underscores :angry:

That’s the reason my fixture for the table user_libraries wasn’t loaded. I created the table userLibraries, and the Gii model and CRUD creators wanted to overwrite my existing files. That means two different table names can result in the same files, and even though the contents differ slightly the result doesn’t work with fixtures.

Note to self and others: don’t use underscores in table names, even though MySQL supports it.

Thanks for all the help :P