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

Python db.create_primary_key函数代码示例

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

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



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

示例1: backwards

 def backwards(self, orm):
     db.drop_primary_key("cmsplugin_picturepublic")
     db.rename_column("cmsplugin_picturepublic", "cmspluginpublic_ptr_id", "publiccmsplugin_ptr_id")
     db.create_primary_key("cmsplugin_picturepublic", ("publiccmsplugin_ptr_id",))
     db.rename_table("cmsplugin_picture", "picture_picture")
     db.rename_table("cmsplugin_picturepublic", "picture_publicpicture")
     db.alter_column('cmsplugin_picture', 'public_id', orm['picture.picture:public'])
开发者ID:artemrizhov,项目名称:itcm,代码行数:7,代码来源:0005_table_rename.py


示例2: forwards

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


示例3: test_primary_key

    def test_primary_key(self):
        """
        Test the primary key operations
        """

        # SQLite backend doesn't support this yet.
        if db.backend_name == "sqlite3":
            return

        db.create_table(
            "test_pk",
            [
                ("id", models.IntegerField(primary_key=True)),
                ("new_pkey", models.IntegerField()),
                ("eggs", models.IntegerField(unique=True)),
            ],
        )
        db.execute_deferred_sql()
        # Remove the default primary key, and make eggs it
        db.drop_primary_key("test_pk")
        db.create_primary_key("test_pk", "new_pkey")
        # Try inserting a now-valid row pair
        db.execute("INSERT INTO test_pk (id, new_pkey, eggs) VALUES (1, 2, 3)")
        db.execute("INSERT INTO test_pk (id, new_pkey, eggs) VALUES (1, 3, 4)")
        db.delete_table("test_pk")
开发者ID:M15t,项目名称:gxdy,代码行数:25,代码来源:db.py


示例4: 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


示例5: backwards

    def backwards(self, orm):
        # Deleting field 'Subsite.id'
        db.delete_column(u'brainstorm_subsite', u'id')


        # Changing field 'Subsite.slug'
        db.alter_column(u'brainstorm_subsite', 'slug', self.gf('django.db.models.fields.SlugField')(max_length=50, primary_key=True))
        # Adding primary key on 'Subsite', fields ['slug']
        db.create_primary_key(u'brainstorm_subsite', ['slug'])
开发者ID:crdunwel,项目名称:tcamp,代码行数:9,代码来源:0003_auto__add_field_subsite_id__chg_field_subsite_slug__del_unique_subsite.py


示例6: backwards

    def backwards(self, orm):
        
        # Deleting field 'Rating.id'
        db.delete_column('cg_channel_rating', 'id')
        
        db.delete_index('cg_channel_rating', 'user_id')
        db.delete_index('cg_channel_rating', 'channel_id')

        db.create_primary_key('cg_channel_rating', ('channel_id', 'user_id'))
开发者ID:kmshi,项目名称:miroguide,代码行数:9,代码来源:0002_add_id.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):
     drop_tko_perf_view = """
     DROP VIEW IF EXISTS tko_perf_view
     """
     db.execute(drop_tko_perf_view)
     drop_tko_perf_view_2 = """
     DROP VIEW IF EXISTS tko_perf_view_2
     """
     db.execute(drop_tko_perf_view_2)
     db.delete_index('tko_iteration_result', 'test_idx')
     db.create_primary_key('tko_iteration_result', ['test_idx'])
开发者ID:Acidburn0zzz,项目名称:autotest,代码行数:11,代码来源:0004_tko_graphing.py


示例9: forwards

    def forwards(self, orm):
        # Changing field 'AssetCategory.id' (serial)
        # to 'AssetCategory.slug' (slugfield)
        db.add_column('ralph_assets_assetcategory', 'slug',
                      self.gf('django.db.models.fields.SlugField')(default='slug',
                      unique=False, max_length=100),
                      keep_default=False)
        db.add_column('ralph_assets_asset', 'category_new_id',
                      self.gf('django.db.models.fields.SlugField')(null=True,
                      unique=False, max_length=100, db_index=False))
        db.add_column('ralph_assets_assetcategory', 'parent_new_id',
                      self.gf('django.db.models.fields.SlugField')(null=True,
                      unique=False, max_length=100, db_index=False))
        db.add_column('ralph_assets_assetmodel', 'category_new_id',
                      self.gf('django.db.models.fields.SlugField')(null=True,
                      unique=False, max_length=100, db_index=False))

        db.start_transaction()

        for id in db.execute(
            'SELECT id FROM ralph_assets_assetcategory WHERE parent_id IS NULL'):
            self.update_slug_and_child(id)

        db.commit_transaction()

        db.create_unique(u'ralph_assets_assetcategory', ['slug'])
        db.delete_foreign_key("ralph_assets_asset", "category_id")
        db.delete_foreign_key("ralph_assets_assetmodel", "category_id")
        db.delete_foreign_key("ralph_assets_assetcategory", "parent_id")
        db.delete_column('ralph_assets_assetcategory', 'parent_id')
        db.delete_column('ralph_assets_assetcategory', 'id')
        db.create_primary_key("ralph_assets_assetcategory", ["slug"])
        db.send_create_signal('ralph_assets', ['ralph_assets_assetcategory'])
        db.rename_column('ralph_assets_assetcategory', 'parent_new_id', 'parent_id')
        db.delete_column('ralph_assets_asset', 'category_id')
        db.rename_column('ralph_assets_asset', 'category_new_id', 'category_id')
        db.delete_column('ralph_assets_assetmodel', 'category_id')
        db.rename_column('ralph_assets_assetmodel', 'category_new_id', 'category_id')
        db.create_index('ralph_assets_assetcategory', ['parent_id'], unique=False)
        db.create_index('ralph_assets_asset', ['category_id'], unique=False)
        db.create_index('ralph_assets_assetmodel', ['category_id'], unique=False)
        sql = db.foreign_key_sql('ralph_assets_asset',
            'category_id', 'ralph_assets_assetcategory', 'slug')
        db.execute(sql)
        sql = db.foreign_key_sql('ralph_assets_assetmodel',
            'category_id', 'ralph_assets_assetcategory', 'slug')
        db.execute(sql)
        sql = db.foreign_key_sql('ralph_assets_assetcategory',
            'parent_id', 'ralph_assets_assetcategory', 'slug')
        db.execute(sql)
        try:
            db.delete_unique('ralph_assets_assetcategory', ['name'])
        except ValueError:
            pass
开发者ID:allegro,项目名称:ralph_assets,代码行数:54,代码来源:0011_auto__add_field_assetcategory_slug.py


示例10: 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:gointer3,项目名称:django-cms,代码行数:11,代码来源:0004_table_rename.py


示例11: backwards

    def backwards(self, orm):
        # Removing unique constraint on 'LeaderboardStanding', fields ['ranking', 'metric']
        db.delete_unique(u'links_leaderboardstanding', ['ranking', 'metric'])

        # Deleting field 'LeaderboardStanding.id'
        db.delete_column(u'links_leaderboardstanding', u'id')


        # Changing field 'LeaderboardStanding.ranking'
        db.alter_column(u'links_leaderboardstanding', 'ranking', self.gf('django.db.models.fields.PositiveIntegerField')(primary_key=True))
        # Adding primary key index on 'LeaderboardStanding', fiels['ranking']
        db.create_primary_key(u'links_leaderboardstanding', [u'ranking'])
开发者ID:15776950506,项目名称:affiliates,代码行数:12,代码来源:0007_auto__add_field_leaderboardstanding_id__chg_field_leaderboardstanding_.py


示例12: 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


示例13: forwards

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


示例14: forwards

 def forwards(self, orm):
     if not table_exists('microsite_microsite'):
         # Adding model 'MicroSite'
         db.create_table('microsite_microsite', (
             ('basesection_ptr', self.gf('django.db.models.fields.related.OneToOneField')(to=orm['section.BaseSection'], unique=True, primary_key=True)),
         ))
         db.send_create_signal('microsite', ['MicroSite'])
     else:
         db.delete_primary_key('microsite_microsite')
         db.create_primary_key('microsite_microsite', ['basesection_ptr_id'])
         db.delete_column('microsite_microsite', 'section_ptr_id')
         db.alter_column('microsite_microsite', 'basesection_ptr_id', models.ForeignKey(orm['section.BaseSection'], null=False, blank=False))
         db.delete_table('section_section')
开发者ID:creativify,项目名称:merengueproj,代码行数:13,代码来源:0001_initial.py


示例15: 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


示例16: backwards

    def backwards(self, orm):
        db.rename_column('pricing_volume_type_resource', 'resource_ptr_id', 'resource_id')
        db.delete_column('pricing_volume_type_resource', u'id')
        db.alter_column('pricing_volume_type_resource', 'os_volume_type_id', self.gf('django.db.models.fields.CharField')(unique=True, max_length=36, db_index=False))
        db.delete_index('pricing_volume_type_resource', ['os_volume_type_id'])
        db.rename_column('pricing_volume_type_resource', 'os_volume_type_id', 'os_type_id')
        db.create_primary_key('pricing_volume_type_resource', ['os_type_id'])
        db.add_column('pricing_volume_type_resource', 'description', self.gf('django.db.models.fields.CharField')(max_length=100))

        db.alter_column('pricing_instance_flavor_resource', 'id', self.gf('django.db.models.fields.IntegerField')(primary_key=True))
        db.delete_index('pricing_instance_flavor_resource', ['os_instance_type_id'])
        db.rename_column('pricing_instance_flavor_resource', 'os_instance_type_id', 'os_flavor_id')
        db.rename_column('pricing_instance_flavor_resource', 'resourcebase_ptr_id', 'resource_id')
        db.alter_column('pricing_instance_flavor_resource', 'resource_id', self.gf('django.db.models.fields.IntegerField')(blank=False))
        db.delete_column('pricing_instance_flavor_resource', u'id')
        db.create_primary_key('pricing_instance_flavor_resource', ['os_flavor_id'])
        db.add_column('pricing_instance_flavor_resource', 'description', self.gf('django.db.models.fields.CharField')(max_length=100))
开发者ID:kili,项目名称:dashboard,代码行数:17,代码来源:0002_change_resource_price_relationship.py


示例17: test_primary_key

 def test_primary_key(self):
     """
     Test the primary key operations
     """
     
     db.create_table("test_pk", [
         ('id', models.IntegerField(primary_key=True)),
         ('new_pkey', models.IntegerField()),
         ('eggs', models.IntegerField(unique=True)),
     ])
     db.execute_deferred_sql()
     # Remove the default primary key, and make eggs it
     db.delete_primary_key("test_pk")
     db.create_primary_key("test_pk", "new_pkey")
     # Try inserting a now-valid row pair
     db.execute("INSERT INTO test_pk (id, new_pkey, eggs) VALUES (1, 2, 3)")
     db.execute("INSERT INTO test_pk (id, new_pkey, eggs) VALUES (1, 3, 4)")
     db.delete_table("test_pk")
开发者ID:TradeHill2011,项目名称:south,代码行数:18,代码来源:db.py


示例18: test_primary_key

 def test_primary_key(self):
     """
     Test the primary key operations
     """
     db.create_table(
         "test_pk",
         [
             ("id", models.IntegerField(primary_key=True)),
             ("new_pkey", models.IntegerField()),
             ("eggs", models.IntegerField(unique=True)),
         ],
     )
     db.execute_deferred_sql()
     db.start_transaction()
     # Remove the default primary key, and make eggs it
     db.drop_primary_key("test_pk")
     db.create_primary_key("test_pk", "new_pkey")
     # Try inserting a now-valid row pair
     db.execute("INSERT INTO test_pk (id, new_pkey, eggs) VALUES (1, 2, 3), (1, 3, 4)")
     db.rollback_transaction()
     db.delete_table("test_pk")
开发者ID:qiwihui,项目名称:johan-doc,代码行数:21,代码来源:db.py


示例19: forwards

    def forwards(self, orm):
        # Deleting field 'BaseSection.status'
        db.delete_column('section_basesection', 'status')

        # Deleting field 'BaseSection.slug'
        db.delete_column('section_basesection', 'slug')

        # Deleting field 'BaseSection.main_image'
        db.delete_column('section_basesection', 'main_image')

        # Deleting field 'BaseSection.id'
        db.delete_column('section_basesection', 'id')

        for field in ('name', 'description', 'plain_description', ):
            for lang, lang_name in settings.LANGUAGES:
                db.delete_column('section_basesection', get_real_fieldname(field, lang))

        # Swapping primary key from id to basecontent_ptr_id
        db.create_primary_key('section_basesection', ['basecontent_ptr_id'])

        # Add new foreign key to section_basesection_related_content.basesection_id
        db.alter_column('section_basesection_related_content', 'basesection_id', models.ForeignKey(orm['section.BaseSection'], null=False, blank=False))
开发者ID:creativify,项目名称:merengueproj,代码行数:22,代码来源:0018_section_as_base_content_step3.py


示例20: forwards

    def forwards(self, orm):
        # create assessment answer model
        db.create_table(u'scorystapp_submission', (
            (u'id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
            ('assessment', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['scorystapp.Assessment'])),
            ('course_user1', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['scorystapp.CourseUser'], null=True, blank=True)),
            ('released1', self.gf('django.db.models.fields.BooleanField')(default=False)),
            ('page_count1', self.gf('django.db.models.fields.IntegerField')()),
            ('pdf1', self.gf('django.db.models.fields.files.FileField')(max_length=100))
        ))
        db.send_create_signal(u'scorystapp', ['Submission'])

        # add submission_ptr field for primary key
        db.add_column(u'scorystapp_examanswer', 'submission_ptr',
                      self.gf('django.db.models.fields.related.ForeignKey')(to=orm['scorystapp.Submission'], null=True),
                      keep_default=False)

        # create assessment that corresponds to each exam
        db.start_transaction()
        for exam_answer in orm.ExamAnswer.objects.all():
            submission = orm.Submission(id=exam_answer.id, course_user1=exam_answer.course_user,
                released1=exam_answer.released, assessment=exam_answer.exam, page_count1=exam_answer.page_count,
                pdf1=exam_answer.pdf)
            submission.save()

            exam_answer.submission_ptr = submission
            exam_answer.save()
        db.commit_transaction()

        # convert submission_ptr_id to primary key
        db.create_unique(u'scorystapp_examanswer', ['submission_ptr_id'])
        db.delete_column(u'scorystapp_examanswer', u'id')
        db.create_primary_key(u'scorystapp_examanswer', [u'submission_ptr_id'])

        # delete exam answer columns that we put into assessment answer
        db.delete_column(u'scorystapp_examanswer', 'course_user_id')
        db.delete_column(u'scorystapp_examanswer', 'released')
        db.delete_column(u'scorystapp_examanswer', 'exam_id')
开发者ID:catherinelu,项目名称:scoryst,代码行数:38,代码来源:0006_manual__add_assessment_answer_parent_table.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python db.create_table函数代码示例发布时间:2022-05-27
下一篇:
Python db.create_index函数代码示例发布时间: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