• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python db.delete_foreign_key函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中south.db.db.delete_foreign_key函数的典型用法代码示例。如果您正苦于以下问题:Python delete_foreign_key函数的具体用法?Python delete_foreign_key怎么用?Python delete_foreign_key使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了delete_foreign_key函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: forwards

    def forwards(self, orm):
        
        # It's not a foreign key anymore, it's just a primary key field
        db.delete_foreign_key('pagelets_pagelet', 'pageletbase_ptr_id')
        db.alter_column('pagelets_pagelet', 'pageletbase_ptr_id', self.gf('django.db.models.fields.IntegerField')())

        # Renaming field 'Pagelet.pageletbase_ptr' to 'id'
        db.rename_column('pagelets_pagelet', 'pageletbase_ptr_id', 'id')

        # Adding field 'Pagelet.creation_date'
        db.add_column('pagelets_pagelet', 'creation_date', self.gf('django.db.models.fields.DateTimeField')(null=True), keep_default=False)

        # Adding field 'Pagelet.created_by'
        db.add_column('pagelets_pagelet', 'created_by', self.gf('django.db.models.fields.related.ForeignKey')(related_name='pagelets_pagelet_created', null=True, to=orm[user_orm_label]), keep_default=False)

        # Adding field 'Pagelet.last_changed'
        db.add_column('pagelets_pagelet', 'last_changed', self.gf('django.db.models.fields.DateTimeField')(null=True), keep_default=False)

        # Adding field 'Pagelet.modified_by'
        db.add_column('pagelets_pagelet', 'modified_by', self.gf('django.db.models.fields.related.ForeignKey')(related_name='pagelets_pagelet_last_modified', null=True, to=orm[user_orm_label]), keep_default=False)

        # Renaming field 'Page.pageletbase_ptr' to 'id'
        db.rename_column('pagelets_page', 'pageletbase_ptr_id', 'id')

        # Adding field 'Page.creation_date'
        db.add_column('pagelets_page', 'creation_date', self.gf('django.db.models.fields.DateTimeField')(null=True), keep_default=False)

        # Adding field 'Page.created_by'
        db.add_column('pagelets_page', 'created_by', self.gf('django.db.models.fields.related.ForeignKey')(related_name='pagelets_page_created', null=True, to=orm[user_orm_label]), keep_default=False)

        # Adding field 'Page.last_changed'
        db.add_column('pagelets_page', 'last_changed', self.gf('django.db.models.fields.DateTimeField')(null=True), keep_default=False)

        # Adding field 'Page.modified_by'
        db.add_column('pagelets_page', 'modified_by', self.gf('django.db.models.fields.related.ForeignKey')(related_name='pagelets_page_last_modified', null=True, to=orm[user_orm_label]), keep_default=False)
开发者ID:pureblue,项目名称:django-pagelets,代码行数:35,代码来源:0002_add_base_fields_to_page_pagelet.py


示例2: forwards

    def forwards(self, orm):
        
        # Deleting field 'MessageLog.parent_id'
        #db.delete_foreign_key('message_log_messagelog', 'parent_id_id')
        db.delete_column('message_log_messagelog', 'parent_id_id')

        # Deleting field 'MessageLog.revision_after'
        db.delete_foreign_key('message_log_messagelog', 'revision_after_id')
        db.delete_column('message_log_messagelog', 'revision_after_id')

        # Deleting field 'MessageLog.revision_before'
        db.delete_foreign_key('message_log_messagelog', 'revision_before_id')
        db.delete_column('message_log_messagelog', 'revision_before_id')

        # Adding field 'MessageLog.revision'
        db.add_column('message_log_messagelog', 'revision', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['reversion.Revision'], null=True, blank=True), keep_default=False)

        # Adding field 'MessageLog.uuid'
        db.add_column('message_log_messagelog', 'uuid', self.gf('django.db.models.fields.CharField')(default='', max_length=36, db_index=True), keep_default=False)

        # Adding field 'MessageLog.parent_uuid'
        db.add_column('message_log_messagelog', 'parent_uuid', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=36, null=True, blank=True), keep_default=False)

        # Adding field 'MessageLog.group_uuid'
        db.add_column('message_log_messagelog', 'group_uuid', self.gf('django.db.models.fields.CharField')(db_index=True, max_length=36, null=True, blank=True), keep_default=False)
开发者ID:freevoid,项目名称:yawf,代码行数:25,代码来源:0004_log_refactor.py


示例3: backwards

 def backwards(self, orm):
     db.delete_foreign_key('cmsplugin_flash' ,'public_id')
     db.drop_primary_key("cmsplugin_flashpublic")
     db.rename_column("cmsplugin_flashpublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_flashpublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_flash", "flash_flash")
     db.rename_table("cmsplugin_flashpublic", "flash_publicflash")
     db.alter_column('cmsplugin_flash', 'public_id', orm['flash.flash:public'])
开发者ID:aronchi,项目名称:django-cms-2.0,代码行数:8,代码来源:0004_table_rename.py


示例4: forwards

 def forwards(self, orm):
     db.delete_foreign_key('fccpublicfiles_politicalbuy', 'publicdocument_ptr_id')
     db.rename_column('fccpublicfiles_politicalbuy', 'publicdocument_ptr_id', 'id')
     db.execute_many('''
         create sequence fccpublicfiles_politicalbuy_id_seq;
         select setval('fccpublicfiles_politicalbuy_id_seq', max(id)) from fccpublicfiles_publicdocument;
         alter table fccpublicfiles_politicalbuy alter column id set default nextval('fccpublicfiles_politicalbuy_id_seq');
     ''')
开发者ID:dwillis,项目名称:fcc_political_ads,代码行数:8,代码来源:0008_reconfigure_pk_on_politicalbuy.py


示例5: backwards

 def backwards(self, orm):
     db.delete_foreign_key("cmsplugin_file", "public_id")
     db.drop_primary_key("cmsplugin_filepublic")
     db.rename_column("cmsplugin_filepublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_filepublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_file", "file_file")
     db.rename_table("cmsplugin_filepublic", "file_publicfile")
     db.alter_column("cmsplugin_file", "public_id", orm["file.file:public"])
开发者ID:aronchi,项目名称:django-cms-2.0,代码行数:8,代码来源:0004_table_rename.py


示例6: clean_constraints

 def clean_constraints(t1, c1, t2, c2):
     # Workaround for http://south.aeracode.org/ticket/775
     if db.backend_name != "sqlite3":
         try:
             db.delete_foreign_key(t1, c1)
             db.execute(db.foreign_key_sql(t1, c1, t2, c2))
         except ValueError as e:
             print("Warning: Could not clean up constraints (this may be harmless): %s" % (e))
开发者ID:alain-andre,项目名称:pootle,代码行数:8,代码来源:0011_update_user_to_profile.py


示例7: backwards

 def backwards(self, orm): 
     db.delete_foreign_key('cmsplugin_text' ,'public_id')
     db.drop_primary_key("cmsplugin_textpublic")
     
     db.rename_column("cmsplugin_textpublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_textpublic", ("publiccmsplugin_ptr_id",))      
     db.foreign_key_sql('cmsplugin_text' ,'public_id', 'cmsplugin_textpublic', "publiccmsplugin_ptr_id")
     db.rename_table("cmsplugin_text", "text_text")
     db.rename_table("cmsplugin_textpublic", "text_publictext")
     db.alter_column('cmsplugin_text', 'public_id', orm['text.text:public'])
开发者ID:aronchi,项目名称:django-cms-2.0,代码行数:10,代码来源:0004_table_rename.py


示例8: backwards

 def backwards(self, orm):
     try:
         db.delete_foreign_key('cmsplugin_file' ,'public_id')
     except:
         pass
     db.drop_primary_key("cmsplugin_filepublic")
     db.rename_column("cmsplugin_filepublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_filepublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_file", "file_file")
     db.rename_table("cmsplugin_filepublic", "file_publicfile")
     db.alter_column('file_file', 'public_id', orm['file.file:public'])
开发者ID:Axion,项目名称:django-cms,代码行数:11,代码来源:0004_table_rename.py


示例9: forwards

 def forwards(self, orm):
     db.rename_table("text_text", "cmsplugin_text")
     db.rename_table("text_publictext", "cmsplugin_textpublic")
     db.rename_column("cmsplugin_textpublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
     db.alter_column("cmsplugin_text", "public_id", orm["text.text:public"])
     try:
         db.delete_foreign_key("cmsplugin_text", "public_id")
     except:
         pass
     db.drop_primary_key("cmsplugin_textpublic")
     db.create_primary_key("cmsplugin_textpublic", ("cmspluginpublic_ptr_id",))
     db.foreign_key_sql("cmsplugin_text", "public_id", "cmsplugin_textpublic", "cmspluginpublic_ptr_id")
开发者ID:wedontplayfair,项目名称:django-cms-2.0,代码行数:12,代码来源:0004_table_rename.py


示例10: forwards

    def forwards(self, orm):

        db.rename_table("link_link", "cmsplugin_link")
        db.rename_table("link_publiclink", "cmsplugin_linkpublic")
        db.rename_column("cmsplugin_linkpublic", "publiccmsplugin_ptr_id", "cmspluginpublic_ptr_id")
        db.alter_column("cmsplugin_link", "public_id", orm["link.link:public"])
        try:
            db.delete_foreign_key("cmsplugin_link", "public_id")
        except:
            pass
        db.drop_primary_key("cmsplugin_linkpublic")
        db.create_primary_key("cmsplugin_linkpublic", ("cmspluginpublic_ptr_id",))
        db.foreign_key_sql("cmsplugin_link", "public_id", "cmsplugin_linkpublic", "cmspluginpublic_ptr_id")
开发者ID:gointer3,项目名称:django-cms,代码行数:13,代码来源:0006_table_rename.py


示例11: test_recursive_foreign_key_delete

 def test_recursive_foreign_key_delete(self):
     """
     Test that recursive foreign keys are deleted correctly (see #1065)
     """
     Test = db.mock_model(model_name='Test', db_table='test_rec_fk_del',
                          db_tablespace='', pk_field_name='id',
                          pk_field_type=models.AutoField, pk_field_args=[])
     db.create_table('test_rec_fk_del', [
         ('id', models.AutoField(primary_key=True, auto_created=True)),
         ('fk', models.ForeignKey(Test)),
     ])
     db.execute_deferred_sql()
     db.delete_foreign_key('test_rec_fk_del', 'fk_id')
开发者ID:10sr,项目名称:hue,代码行数:13,代码来源:db.py


示例12: forwards

 def forwards(self, orm):
     try:
         db.delete_foreign_key('sentry_message', 'group_id')
         db.delete_foreign_key('sentry_message', 'project_id')
         db.delete_foreign_key('sentry_eventmapping', 'group_id')
         db.delete_foreign_key('sentry_eventmapping', 'project_id')
     except OperationalError:
         pass
开发者ID:280185386,项目名称:sentry,代码行数:8,代码来源:0229_drop_event_constraints.py


示例13: forwards

    def forwards(self, orm):
        # OMFG Get ready, we're going to change the primary key!
        # Doing bad things, disabling triggers
        db.execute("ALTER TABLE brainstorm_idea DISABLE TRIGGER ALL;")

        # Dropping foreign key constraint
        db.delete_foreign_key('brainstorm_idea', 'subsite_id')
        db.execute('DROP INDEX brainstorm_idea_subsite_id_like')
        db.delete_index('brainstorm_idea', ['subsite_id'])

        # Removing primary key on 'Subsite', fields ['slug']
        db.delete_primary_key(u'brainstorm_subsite')

        # Adding primary key field 'Subsite.id'
        db.add_column(u'brainstorm_subsite', u'id',
                      self.gf('django.db.models.fields.IntegerField')(blank=True, null=True))

        # WOW. Have to manually create AutoFields. Thanks Django!
        db.execute('CREATE SEQUENCE brainstorm_subsite_id_seq;')
        db.execute("UPDATE brainstorm_subsite SET id = nextval('brainstorm_subsite_id_seq');")
        db.execute("ALTER TABLE brainstorm_subsite ALTER COLUMN id SET DEFAULT nextval('brainstorm_subsite_id_seq');")
        db.execute('ALTER SEQUENCE brainstorm_subsite_id_seq OWNED BY brainstorm_subsite.id;')
        db.execute("SELECT setval('brainstorm_subsite_id_seq', q.i) FROM(SELECT MAX(id) i FROM brainstorm_subsite) q;")

        # Now make it the pk
        db.create_primary_key('brainstorm_subsite', ['id'])

        # Updating foreign key values
        db.execute('''UPDATE brainstorm_idea idea
                      SET subsite_id = subsite.id
                      FROM brainstorm_subsite subsite
                      WHERE(idea.subsite_id = subsite.slug);''')

        # Casting the fk to an integer
        db.execute("ALTER TABLE brainstorm_idea ALTER COLUMN subsite_id TYPE integer USING CAST(subsite_id AS integer);")

        # Re-adding foreign key constraint
        fk_sql = db.foreign_key_sql('brainstorm_idea', 'subsite_id', 'brainstorm_subsite', 'id')
        db.execute(fk_sql)

        # Changing field 'Subsite.slug' to a plain old slugfield
        db.alter_column(u'brainstorm_subsite', 'slug', self.gf('django.db.models.fields.SlugField')(max_length=50))

        # Adding unique constraint on 'Subsite', fields ['slug']
        db.create_unique(u'brainstorm_subsite', ['slug'])

        # Re-enabling triggers
        db.execute("ALTER TABLE brainstorm_idea ENABLE TRIGGER ALL;")
开发者ID:crdunwel,项目名称:tcamp,代码行数:48,代码来源:0003_auto__add_field_subsite_id__chg_field_subsite_slug__del_unique_subsite.py


示例14: delete_dynamic_tables

def delete_dynamic_tables(*names):
    db.start_transaction()
    for model in get_dynamic_models(*names):
        for f in model._meta.fields:
            if isinstance(f, models.ForeignKey):
                try:
                    db.delete_foreign_key(model._meta.db_table, f.column)
                except ValueError:
                    pass
    transaction.commit_unless_managed()

    db.start_transaction()
    for model in get_dynamic_models(*names):
        db.delete_table(model._meta.db_table, cascade=True)
    #db.commit_transaction()
    transaction.commit_unless_managed()
开发者ID:pombredanne,项目名称:django-dymo,代码行数:16,代码来源:test.py


示例15: backwards

    def backwards(self, orm):
        db.rename_table('socialmedia_socialmedia', 'utils_socialmedia')

        if not db.dry_run:
            # For permissions to work properly after migrating
            orm['contenttypes.contenttype'].objects.filter(app_label='socialmedia', model='socialmedia').update(app_label='utils')

            # Fix foreign key for accounts
            db.delete_foreign_key('accounts_account_social_media', 'socialmedia_id')
            sql = db.foreign_key_sql('accounts_account_social_media', 'socialmedia_id', 'utils_socialmedia', 'id')
            db.execute(sql)

            # Fix foreign key for contacts
            db.delete_foreign_key('contacts_contact_social_media', 'socialmedia_id')
            sql = db.foreign_key_sql('contacts_contact_social_media', 'socialmedia_id', 'utils_socialmedia', 'id')
            db.execute(sql)
开发者ID:rmoorman,项目名称:hellolily,代码行数:16,代码来源:0010_auto__move_socialmedia.py


示例16: forwards

    def forwards(self, orm):
        if (db.backend_name == 'mysql'):
            #case mysql db it is necessary :/
            db.delete_foreign_key('chat_userlinks', 'user_id')
            db.delete_foreign_key('chat_userlinks', 'link_id')

        # Removing unique constraint on 'UserLinks', fields ['user']
        db.delete_unique('chat_userlinks', ['user_id'])

        # Removing unique constraint on 'UserLinks', fields ['link']
        db.delete_unique('chat_userlinks', ['link_id'])

        # Changing field 'UserLinks.link'
        db.alter_column('chat_userlinks', 'link_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['chat.Links']))

        # Changing field 'UserLinks.user'
        db.alter_column('chat_userlinks', 'user_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['auth.User']))
开发者ID:hjemmel,项目名称:chat-github,代码行数:17,代码来源:0002_auto__chg_field_userlinks_link__del_unique_userlinks_link__chg_field_u.py


示例17: innodb_ready_rename_column

def innodb_ready_rename_column(orm, models, table, old_column_name, new_column_name, app_model, new_field_name):
    """
    Foreign key renaming which works for InnoDB
    More: http://south.aeracode.org/ticket/466

    Parameters:
    - orm: a reference to 'orm' parameter passed to Migration.forwards()/backwards()
    - models: reference to Migration.models data structure
    - table: e.g. 'askbot_thread'
    - old_column_name: e.g. 'question_post_id'
    - new_column_name: e.g. 'question_id'
    - app_model: e.g. 'askbot.thread' (should be a dict key into 'models')
    - new_field_name: e.g. 'question' (usually it's same as new_column_name, only without trailing '_id')
    """
    use_workaround = houston_do_we_have_a_problem(table)

    # ditch the foreign key
    if use_workaround:
        db.delete_foreign_key(table, old_column_name)

    # rename column
    db.rename_column(table, old_column_name, new_column_name)

    # restore the foreign key
    if not use_workaround:
        return

    model_def = models[app_model][new_field_name]
    assert model_def[0] == "django.db.models.fields.related.ForeignKey"
    # Copy the dict so that we don't change the original
    # (otherwise the dry run would change it for the "normal" run
    #  and the latter would try to convert str to model once again)
    fkey_params = model_def[2].copy()
    assert "to" in fkey_params
    assert fkey_params["to"].startswith("orm['")
    assert fkey_params["to"].endswith("']")
    fkey_params["to"] = orm[fkey_params["to"][5:-2]]  # convert "orm['app.models']" string to actual model
    field = ask_for_it_by_name(model_def[0])(**fkey_params)
    # INFO: ask_for_it_by_name() if equivalent to self.gf() which is usually used in migrations, e.g.:
    #          db.alter_column('askbot_badgedata', 'slug', self.gf('django.db.models.fields.SlugField')(unique=True, max_length=50))
    db.alter_column(table, new_column_name, field)
    db.clear_deferred_sql()
开发者ID:vuquangchien,项目名称:tech.fpt.com.vn,代码行数:42,代码来源:__init__.py


示例18: forwards

    def forwards(self, orm):
        db.create_table('section_sectioncontentmapping', (
            ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('old_id', self.gf('django.db.models.fields.IntegerField')(unique=True)),
            ('new_id', self.gf('django.db.models.fields.IntegerField')(unique=True)),
        ))

        if not table_exists('microsite_microsite'):
            # Deleting model 'Section'
            db.delete_table('section_section')
        else:
            # Adding field 'MicroSite.basesection_ptr'
            db.add_column('microsite_microsite', 'basesection_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['section.BaseSection'], null=True), keep_default=False)
            if db.backend_name not in ['sqlite3', 'mysql']:
                db.delete_foreign_key('section_section', 'basesection_ptr_id')

        # Adding field 'BaseSection.basecontent_ptr'
        db.add_column('section_basesection', 'basecontent_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['base.BaseContent'], null=True), keep_default=False)
        if db.backend_name not in ['sqlite3', 'mysql']:
            db.delete_foreign_key('section_basesection_related_content', 'basesection_id')
开发者ID:creativify,项目名称:merengueproj,代码行数:20,代码来源:0016_section_as_base_content_step1.py


示例19: forwards

    def forwards(self, orm):
        "Make remote_id Primary Key"

        # Remove PK from Album
        db.delete_foreign_key('vkontakte_photos_photo', 'album_id')

        photos = orm.Photo.objects.only('album').all()  #

        for p in photos:
            album = orm.Album.objects.get(id=p.album_id)
            p.album_id = album.remote_id
            p.save()

        db.delete_primary_key('vkontakte_photos_album')
        #db.delete_column(u'vkontakte_photos_album', u'id')

        db.create_primary_key('vkontakte_photos_album', ['remote_id'])
        db.alter_column('vkontakte_photos_photo', 'album_id', models.ForeignKey(
            orm['vkontakte_photos.Album'], null=True, blank=True))

        # Remove PK from Photo
        # Remove Foreign key from Comments and likes
        db.delete_foreign_key('vkontakte_photos_comment', 'photo_id')
        db.delete_foreign_key('vkontakte_photos_photo_like_users', 'photo_id')

        db.delete_primary_key('vkontakte_photos_photo')
        #db.delete_column(u'vkontakte_photos_photo', u'id')

        # Create Primary Keys
        db.create_primary_key('vkontakte_photos_photo', ['remote_id'])
开发者ID:Andertaker,项目名称:django-vkontakte-photos,代码行数:30,代码来源:0017_remote_id_primary_key.py


示例20: backwards

    def backwards(self, orm):
        
        # Adding field 'MessageLog.parent_id'
        db.add_column('message_log_messagelog', 'parent_id', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['message_log.MessageLog'], null=True, blank=True), keep_default=False)

        # Adding field 'MessageLog.revision_after'
        db.add_column('message_log_messagelog', 'revision_after', self.gf('django.db.models.fields.related.ForeignKey')(related_name='pre_message', null=True, to=orm['revision.Revision']), keep_default=False)

        # Adding field 'MessageLog.revision_before'
        db.add_column('message_log_messagelog', 'revision_before', self.gf('django.db.models.fields.related.ForeignKey')(related_name='post_message', null=True, to=orm['revision.Revision']), keep_default=False)

        # Deleting field 'MessageLog.revision'
        db.delete_foreign_key('message_log_messagelog', 'revision_id')
        db.delete_column('message_log_messagelog', 'revision_id')

        # Deleting field 'MessageLog.uuid'
        db.delete_column('message_log_messagelog', 'uuid')

        # Deleting field 'MessageLog.parent_uuid'
        db.delete_column('message_log_messagelog', 'parent_uuid')

        # Deleting field 'MessageLog.group_uuid'
        db.delete_column('message_log_messagelog', 'group_uuid')
开发者ID:freevoid,项目名称:yawf,代码行数:23,代码来源:0004_log_refactor.py



注:本文中的south.db.db.delete_foreign_key函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python db.delete_index函数代码示例发布时间:2022-05-27
下一篇:
Python db.delete_column函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap