Yii Framework Forum: Foreign Key Checks During Migrations - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Foreign Key Checks During Migrations Rate Topic: -----

#1 User is offline   hjb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 15-November 11
  • Location:Manchester, UK

Posted 21 August 2013 - 04:01 AM

I've had a good search around and could not find an answer to this, but apologies if it's been shared elsewhere.

I'm going to create and run quite a large migration on an existing database to move it over to a new system and I'd like to disable foreign key checks during it.

Because the migration will be making a fair few changes I'll be using safeUp and safeDown.

So my question is, do I need to disable foreign key checks at the top of the migration and enable again at the bottom? safeUp and safeDown don't do anything clever with foreign key checks already do they?

and if I do need to, what's the best way to do that? There is no built in function similar to $this->addColumn(); so build an sql query and execute it?

Thanks.
0

#2 User is offline   hjb 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 4
  • Joined: 15-November 11
  • Location:Manchester, UK

Posted 21 August 2013 - 10:16 AM

To answer my own question I did need to ignore foreign key constrains so I did...

$this->execute("SET foreign_key_checks = 0;");


...at the top and then...

$this->execute("SET foreign_key_checks = 1;");


...at the bottom of the migration.
1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users