ManyToMany field creation problem

123 views
Skip to first unread message

Mrinmoy Das

unread,
Dec 6, 2013, 7:44:27 AM12/6/13
to django...@googlegroups.com
Hi,

I have these tables


on apps/common/models.py


class UnitType(models.Model):
    title = models.CharField(max_length=50)

    def __unicode__(self):
        return u'%s' % self.title

class UnitPrice(models.Model):
    project = models.ForeignKey('property.Property')
    unit_type = models.ForeignKey(UnitType)

    five_year_target_price = models.CharField(max_length=50, blank=True, null=True)
    per_sqft_price = models.CharField(max_length=50, blank=True, null=True)
    total_price = models.CharField(max_length=50, blank=True, null=True)
   
    total_area = models.CharField(max_length=140, blank=True, null=True)
    carpet_area = models.CharField(max_length=140, blank=True, null=True)

     def __unicode__(self):
        return u'%s' % self.title



and on apps/property/models.py


class Property(Base):
.....
.....
    unit_price = models.ManyToManyField(UnitType,through=UnitPrice, blank=True, null=True)

.....
.....



after adding the unit price field I did  a migration

      python manage.py schemamigration property --auto

I am getting this output

       Nothing seems to have changed.

the through table is created,  i have checked that.


                                         Table "public.common_unitprice"
         Column         |          Type          |                           Modifiers                          
------------------------+------------------------+---------------------------------------------------------------
 id                     | integer                | not null default nextval('common_unitprice_id_seq'::regclass)
 project_id             | integer                | not null
 unit_type_id           | integer                | not null
 five_year_target_price | character varying(50)  |
 per_sqft_price         | character varying(50)  |
 total_price            | character varying(50)  |
 total_area             | character varying(140) |
 carpet_area            | character varying(140) |
Indexes:
    "common_unitprice_pkey" PRIMARY KEY, btree (id)
    "common_unitprice_project_id" btree (project_id)
    "common_unitprice_unit_type_id" btree (unit_type_id)
Foreign-key constraints:
    "project_id_refs_id_7c43d44c" FOREIGN KEY (project_id) REFERENCES property_property(id) DEFERRABLE INITIALLY DEFERRED
    "unit_type_id_refs_id_1a1f3765" FOREIGN KEY (unit_type_id) REFERENCES common_unittype(id) DEFERRABLE INITIALLY DEFERRED






Any help??

Daniel Roseman

unread,
Dec 6, 2013, 9:34:43 AM12/6/13
to django...@googlegroups.com
What else are you expecting? If the through table is created, that's all you need.
--
DR.

Mrinmoy Das

unread,
Dec 6, 2013, 9:42:45 AM12/6/13
to django...@googlegroups.com
I cant get the field


unit_price = models.ManyToManyField(UnitType,through=UnitPrice, blank=True, null=True)

in Property table.

After adding the field, I tried doing a schemamigration, but output says  "No change has been done"


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0b766e73-adf4-42a9-9085-524687de9f50%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Chi Tak Lam

unread,
Dec 6, 2013, 2:51:03 PM12/6/13
to django...@googlegroups.com
I think you should do a

python manage.py migrate property

after

python manage.py schemamigration property --auto?

Mrinmoy Das

unread,
Dec 6, 2013, 3:34:17 PM12/6/13
to django...@googlegroups.com
Any help guys??

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Daniel Roseman

unread,
Dec 6, 2013, 6:39:53 PM12/6/13
to django...@googlegroups.com
As I've already said, you don't need any help. If the through table is created, *that is all you need*.
--
DR.

Mrinmoy Das

unread,
Dec 6, 2013, 7:15:32 PM12/6/13
to django...@googlegroups.com
Hi Daniel,

I can always add a field manually, question is why does not south does it. :)
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.

Daniel Roseman

unread,
Dec 6, 2013, 9:18:13 PM12/6/13
to django...@googlegroups.com
On Friday, 6 December 2013 19:15:32 UTC, Mrinmoy Das wrote:
Hi Daniel,

I can always add a field manually, question is why does not south does it. :)

Sigh. One last time, then.

There is no other field. A many-to-many relationship is *only* a through table. Nothing else needs to be created, and nothing else will be created.
--
DR.

Tom Evans

unread,
Dec 9, 2013, 11:32:13 AM12/9/13
to django...@googlegroups.com
On Fri, Dec 6, 2013 at 9:42 AM, Mrinmoy Das <mrinmo...@gmail.com> wrote:
> I cant get the field
>
>
> unit_price = models.ManyToManyField(UnitType,through=UnitPrice, blank=True,
> null=True)
>
> in Property table.
>
> After adding the field, I tried doing a schemamigration, but output says
> "No change has been done"
>

This is because adding that field results in no change - no columns
need to be added to any tables, no columns need to be removed from any
tables and no tables need to be created.

Adding the unit_price field to Property simply informs Django to
create the appropriate properties on the python models so that you can
access the related models, and so South, being a tool for managing
database schema changes, has nothing to do.

Cheers

Tom

Mrinmoy Das

unread,
Dec 10, 2013, 4:49:36 AM12/10/13
to django...@googlegroups.com, teva...@googlemail.com

Hi,

Sorry Daniel for bothering, my understanding of many to many field was pretty shaky :)
Reply all
Reply to author
Forward
0 new messages