Skip to content

disable FOREIGN_KEY_CHECKS on MySQL #115

Closed
wants to merge 5 commits into from

2 participants

@havvg
Propel member
havvg commented Mar 2, 2012

I'm not exactly sure on this. We had the issue when using the DataLoader in setUp of tests that it could not delete entries. This is an issue of every data loader. We currently solved it, by adding the DataWiper before actually loading expected fixtures for the tests.

I think it makes sense to disable the checks here, too.

@willdurand
Propel member

mmh, shouldn't Propel take care of that? Using InnoDB as engine if I remember well

@havvg
Propel member
havvg commented Mar 4, 2012

We use InnoDB, but it causes a foreign key constraints error.

I will setup a testcase, so we can verify why and where exactly it breaks.

@willdurand
Propel member

@havvg poke ?

@havvg
Propel member
havvg commented Mar 7, 2012

Sorry, I have to postpone this one, very busy days. I can't tell, when I will be able to provide the testcase.

@willdurand
Propel member

There is no problem ;)

@willdurand
Propel member

@havvg any news?

@havvg
Propel member
havvg commented May 2, 2012

We are currently on this issue, hopefully we will catch the root cause and provide a fix + tests this week.

@havvg
Propel member
havvg commented May 2, 2012

We added the DataWiper to our testsuite, so it's fine without this change.

However the propel:fixtures:load command does not work without it, if you split up related fixtures in their respective files.
In that case, you have to disable the FK checks, so you can modify the database with all files found one by one.

Another solution would be to merge all found files into one prior actually working down the fixtures content.

<?php
    public function load($files = array(), $connectionName)
    {
            // ..

            $this->con->beginTransaction();

            $datas = array();
            foreach ($files as $file) {
                $content = $this->transformDataToArray($file);

                if (count($content) > 0) {
                    $datas = array_merge($datas, $content);
                    $nbFiles++;
                }
            }

            $this->deleteCurrentData($datas);
            $this->loadDataFromArray($datas);

            $this->con->commit();

            // ..

I would prefer this solution, as it is more generic than adding mysql specific logic.
Let me know, what you think and adjust the PR! @willdurand

@havvg
Propel member
havvg commented May 2, 2012

I mean, I'll adjust the PR :)

@willdurand
Propel member

@havvg to merge fixtures is fine, right? I mean it's the most convenient solution IMO

@havvg
Propel member
havvg commented May 2, 2012

Yep, that's what I'm thinking, too. I'll update this PR soon.

@havvg havvg closed this May 2, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.