Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » Changing a constraint with live data [RSS Feed]

#1 Jan. 4, 2011 10:18:46

Sithembewena L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Changing a constraint with live data


Hi everyone,

Happy 2011.

I am having an interesting problem where I need to change the foreign key on
a model (A) to reference a different model. problem is, the table for A
is populated with records and MySQL does not seem able to drop it. I ran
manage.py sql and would like to drop the existing constraint and add the new
one.
Is there a straightforward way to do this?



--
Regards,
Sithembewena Lloyd Dube

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 Jan. 4, 2011 11:51:26

Thomas G.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Changing a constraint with live data


I use south for migrations. I have done something like this
with south, but with postgres not mysql.

I don't know if mysql supports deferrable foreign key constraints.

Thomas

Sithembewena Lloyd Dube wrote:
> Hi everyone,
>
> Happy 2011.
>
> I am having an interesting problem where I need to change the foreign
> key on a model (A) to reference a different model. problem is, the table
> for A
> is populated with records and MySQL does not seem able to drop it. I ran
> manage.py sql and would like to drop the existing constraint and add the
> new one.
> Is there a straightforward way to do this?

--
Thomas Guettler,http://www.thomas-guettler.de/E-Mail: guettli (*) thomas-guettler + de

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#3 Jan. 4, 2011 16:21:05

Shawn M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Changing a constraint with live data


You could do this with South in multiple steps.

1. South schema migration:
Add the new field for the proper foreign key, but don't make the field
required.

2. South data migration:
Create a migration that appropriately populates the new field based on
whatever rules you have.

3. South schema migration:
Make the new field required, and optionally delete the old field.

Shawn

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#4 Jan. 5, 2011 09:44:36

Sithembewena L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Changing a constraint with live data


Thomas and Shawn, thanks for responding.

South looks pretty useful - I hope that it could be included in the standard
Django distribution.

On Tue, Jan 4, 2011 at 6:20 PM, Shawn Milochik <sh...@milochik.com> wrote:

> You could do this with South in multiple steps.
>
> 1. South schema migration:
> Add the new field for the proper foreign key, but don't make the field
> required.
>
> 2. South data migration:
> Create a migration that appropriately populates the new field based on
> whatever rules you have.
>
> 3. South schema migration:
> Make the new field required, and optionally delete the old field.
>
> Shawn
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>
>


--
Regards,
Sithembewena Lloyd Dube

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#5 Jan. 5, 2011 15:25:10

Shawn M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Changing a constraint with live data


On Jan 5, 2011, at 4:44 AM, Sithembewena Lloyd Dube wrote:

> Thomas and Shawn, thanks for responding.
>
> South looks pretty useful - I hope that it could be included in the standard
> Django distribution.
>

This has been discussed quite a bit, and a plan has been made to do this -- in
a way. South itself won't be integrated into Django, but the South project will
be divided into two separate pieces. One will be built into Django, and will
allow users to make their own migration front-end. The other will be the
third-party South app which you can use to take advantage of the built-in
backend.http://www.aeracode.org/2010/6/2/django-and-migrations/Shawn

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#6 Jan. 7, 2011 11:57:07

Sithembewena L.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Changing a constraint with live data


Thanks Shawn. Great to note that someone has thought of this before.

On Wed, Jan 5, 2011 at 5:24 PM, Shawn Milochik <sh...@milochik.com> wrote:

>
> On Jan 5, 2011, at 4:44 AM, Sithembewena Lloyd Dube wrote:
>
> Thomas and Shawn, thanks for responding.
>
> South looks pretty useful - I hope that it could be included in the
> standard Django distribution.
>
>
> This has been discussed quite a bit, and a plan has been made to do this --
> in a way. South itself won't be integrated into Django, but the South
> project will be divided into two separate pieces. One will be built into
> Django, and will allow users to make their own migration front-end. The
> other will be the third-party South app which you can use to take advantage
> of the built-in backend.
>
>http://www.aeracode.org/2010/6/2/django-and-migrations/>
> Shawn
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-us...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com<django-users%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
>http://groups.google.com/group/django-users?hl=en.
>



--
Regards,
Sithembewena Lloyd Dube

--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

  • Root
  • » Django
  • » Changing a constraint with live data [RSS Feed]

Board footer

Moderator control

Enjoy the 21st of August
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support