Sunday, February 24, 2013

Re: Manually added foreign key not working.

Does anybody can answer this?

Let me know if anything extra is required?

Thanks in advance.......


Laxmikant

On Wed, Feb 20, 2013 at 6:23 PM, laxmikant ratnaparkhi <laxglx01@gmail.com> wrote:
Hello all,

I just run a command to Add foreign key to the existing table. and the command was like this:

ALTER TABLE acfs_subscriptionmaster ADD CONSTRAINT FK_Formats FOREIGN KEY (id) REFERENCES acfs_formats (id) MATCH FULL;

It has got executed. but giving error on the interface

column acfs_subscriptionmaster.FK_Formats_id does not exist
LINE 1: ...ccountmaster"."id") INNER JOIN "acfs_formats" ON ("acfs_subs...

What could be the reason, What Should I do to solve this. I can't DROP Table. ?

my models.py looks like this :

class SubscriptionMaster(models.Model):
    """
    """
    uid = models.TextField(blank=True, null=True)
    FK_SubsType = models.ForeignKey(SubscriptionType)
    FK_Product = models.ForeignKey(ProductMaster)
    FK_Formats = models.ForeignKey(Formats)   <<----------------------------------            Added this field in models.py
    ccs_minimum_price = models.TextField(blank=True, null=True)
    ccs_maximum_price = models.TextField(blank=True, null=True)
    ccs_Increment_type = models.TextField(blank=True, null=True)
    ccs_minimum_increment = models.TextField(blank=True, null=True)
    ccs_maximum_increment = models.TextField(blank=True, null=True)
    ccs_default_offer = models.TextField(blank=True, null=True)

Checked SQL Got created by python manage.py sqlall acfs

This is my table :

CREATE TABLE "acfs_subscriptionmaster" (
    "id" serial NOT NULL PRIMARY KEY,
    "uid" text,
    "FK_SubsType_id" integer NOT NULL REFERENCES "acfs_subscriptiontype" ("id") DEFERRABLE INITIALLY DEFERRED,
    "FK_Product_id" integer NOT NULL REFERENCES "acfs_productmaster" ("id") DEFERRABLE INITIALLY DEFERRED,
    "FK_Formats_id" integer NOT NULL REFERENCES "acfs_formats" ("id") DEFERRABLE INITIALLY DEFERRED, <--------------This field has got created here
    "ccs_minimum_price" text,
    "ccs_maximum_price" text,
    "ccs_Increment_type" text,
    "ccs_minimum_increment" text,
    "ccs_maximum_increment" text,
    "ccs_default_offer" text,
);

Also its howing indexes like this :

CREATE INDEX "acfs_subscriptionformats_FK_Format_id" ON "acfs_subscriptionformats" ("FK_Format_id");
CREATE INDEX "acfs_subscriptionmaster_FK_SubsType_id" ON "acfs_subscriptionmaster" ("FK_SubsType_id");
CREATE INDEX "acfs_subscriptionmaster_FK_Product_id" ON "acfs_subscriptionmaster" ("FK_Product_id");
CREATE INDEX "acfs_subscriptionmaster_FK_Formats_id" ON "acfs_subscriptionmaster" ("FK_Formats_id");

Looks like error is field has not got created in actual database :
python manage.py dbshell
acfsdb1=# SELECT * FROM acfs_subscriptionmaster;
 id | uid | FK_SubsType_id | FK_Product_id | ccs_minimum_price | ccs_maximum_price | ccs_Increment_type | ccs_minimum_increment | ccs_maximum_increment | ccs_default_of
fer | fix_startdatetime | fix_expiydatetime | fix_price | dur_period | wd_field_01 | wd_field_02 | wd_field_03 | wd_field_04 | wd_field_05 | flag_field_01 | created_dat
e_time | modified_date_time
----+-----+----------------+---------------+-------------------+-------------------+--------------------+-----------------------+-----------------------+---------------
----+-------------------+-------------------+-----------+------------+-------------+-------------+-------------+-------------+-------------+---------------+------------
-------+--------------------
(0 rows)

This is my DJANGO - Python versions

Django Version: 1.2.7
Exception Type: DatabaseError
Exception Value:
column acfs_subscriptionmaster.FK_Format_id does not exist  LINE 1: ...ccountmaster"."id") INNER JOIN "acfs_formats" ON ("acfs_subs...                                                               ^  
Exception Location: /usr/lib/python2.6/site-packages/django/db/backends/postgresql_psycopg2/base.py in execute, line 44
Python Executable: /usr/bin/python
Python Version: 2.6.6
postgres 9.1


Traceback Variables (see at the bottom for the error)
Local vars
args
()
e
ProgrammingError('column acfs_subscriptionmaster.FK_Format_id does not exist\nLINE 1: ...ccountmaster"."id") INNER JOIN "acfs_formats" ON ("acfs_subs...\n ^\n',)
query
'SELECT "acfs_subscriptionmaster"."id", "acfs_subscriptionmaster"."uid", "acfs_subscriptionmaster"."FK_SubsType_id", "acfs_subscriptionmaster"."FK_Product_id", "acfs_subscriptionmaster"."FK_Format_id", "acfs_subscriptionmaster"."ccs_minimum_price", "acfs_subscriptionmaster"."ccs_maximum_price", "acfs_subscriptionmaster"."ccs_Increment_type", "acfs_subscriptionmaster"."ccs_minimum_increment", "acfs_subscriptionmaster"."ccs_maximum_increment", "acfs_subscriptionmaster"."ccs_default_offer", "acfs_subscriptionmaster"."fix_startdatetime", "acfs_subscriptionmaster"."fix_expiydatetime", "acfs_subscriptionmaster"."fix_price", "acfs_subscriptionmaster"."dur_period", "acfs_subscriptionmaster"."wd_field_01", "acfs_subscriptionmaster"."wd_field_02", "acfs_subscriptionmaster"."wd_field_03", "acfs_subscriptionmaster"."wd_field_04", "acfs_subscriptionmaster"."wd_field_05", "acfs_subscriptionmaster"."flag_field_01", "acfs_subscriptionmaster"."created_date_time", "acfs_subscriptionmaster"."modified_date_time", "acfs_subscriptiontype"."id", "acfs_subscriptiontype"."substype", "acfs_subscriptiontype"."wd_field_01", "acfs_subscriptiontype"."wd_field_02", "acfs_productmaster"."id", "acfs_productmaster"."uid", "acfs_productmaster"."FK_Account_id", "acfs_productmaster"."product_type", "acfs_productmaster"."product_name", "acfs_productmaster"."product_description", "acfs_productmaster"."product_code", "acfs_productmaster"."author", "acfs_productmaster"."blurb", "acfs_productmaster"."title", "acfs_productmaster"."subtitle", "acfs_productmaster"."keywords", "acfs_productmaster"."subject", "acfs_productmaster"."contributor", "acfs_productmaster"."publisher", "acfs_productmaster"."published_date", "acfs_productmaster"."identifier", "acfs_productmaster"."genre", "acfs_productmaster"."title_sort", "acfs_productmaster"."author_sort", "acfs_productmaster"."relation", "acfs_productmaster"."pricing_type", "acfs_productmaster"."is_empty", "acfs_productmaster"."purchase", "acfs_productmaster"."subscription", "acfs_productmaster"."copyright", "acfs_productmaster"."created_by", "acfs_productmaster"."modified_by", "acfs_productmaster"."workuid", "acfs_productmaster"."wd_field_01", "acfs_productmaster"."wd_field_02", "acfs_productmaster"."wd_field_03", "acfs_productmaster"."wd_field_04", "acfs_productmaster"."wd_field_05", "acfs_productmaster"."flag_field1", "acfs_productmaster"."flag_field2", "acfs_productmaster"."created_date_time", "acfs_productmaster"."modified_date_time", "acfs_accountmaster"."id", "acfs_accountmaster"."uid", "acfs_accountmaster"."account_name", "acfs_accountmaster"."account_url", "acfs_accountmaster"."account_type", "acfs_accountmaster"."active", "acfs_accountmaster"."currency", "acfs_accountmaster"."organization", "acfs_accountmaster"."address1", "acfs_accountmaster"."address2", "acfs_accountmaster"."city", "acfs_accountmaster"."postal_zip", "acfs_accountmaster"."state", "acfs_accountmaster"."country", "acfs_accountmaster"."contact_name", "acfs_accountmaster"."contact_mobile", "acfs_accountmaster"."contact_email", "acfs_accountmaster"."language", "acfs_accountmaster"."maximum_users", "acfs_accountmaster"."maximum_documents", "acfs_accountmaster"."expiry_date", "acfs_accountmaster"."wd_field_01", "acfs_accountmaster"."wd_field_02", "acfs_accountmaster"."wd_field_03", "acfs_accountmaster"."wd_field_04", "acfs_accountmaster"."wd_field_05", "acfs_accountmaster"."flag_field1", "acfs_accountmaster"."flag_field2", "acfs_accountmaster"."created_date_time", "acfs_accountmaster"."modified_date_time", "acfs_accountmaster"."created_by", "acfs_accountmaster"."modified_by", "acfs_formats"."id", "acfs_formats"."uid", "acfs_formats"."format_name", "acfs_formats"."format_type", "acfs_formats"."subscription", "acfs_formats"."wd_field_01", "acfs_formats"."wd_field_02", "acfs_formats"."created_date_time", "acfs_formats"."modified_date_time" FROM "acfs_subscriptionmaster" INNER JOIN "acfs_subscriptiontype" ON ("acfs_subscriptionmaster"."FK_SubsType_id" = "acfs_subscriptiontype"."id") INNER JOIN "acfs_productmaster" ON ("acfs_subscriptionmaster"."FK_Product_id" = "acfs_productmaster"."id") INNER JOIN "acfs_accountmaster" ON ("acfs_productmaster"."FK_Account_id" = "acfs_accountmaster"."id") INNER JOIN "acfs_formats" ON ("acfs_subscriptionmaster"."FK_Format_id" = "acfs_formats"."id") ORDER BY "acfs_subscriptionmaster"."id" DESC'
self
<django.db.backends.postgresql_psycopg2.base.CursorWrapper object at 0x7ff73e389d50>


--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate