2013-01-06 10 views
8

인내심을 기쁘게 생각합니다."정수로 변환 할 수 없습니다"오류

CharField에서 몇 가지 속성을 IntegerField로 변경했습니다. 아래에 나열된 코드입니다 :

rating_choices = (
    (1,"1"), 
    (2,"2"), 
    (3,"3"), 
    (4,"4"), 
    (5,"5"), 
) 

class Rating(models.Model): 
    article = models.ForeignKey(Article,null=True) 
    organization = models.IntegerField(choices=rating_choices, default=1) 
    support = models.IntegerField(choices=rating_choices, default=1) 
    readability = models.IntegerField(choices=rating_choices, default=1) 
    tags = models.IntegerField(choices=rating_choices, default=1) 
    comments = models.TextField() 
    def get_overall_rating(self): 
     return fsum(self.organization + self.support + self.support + self.readability + self.tags)/5.0 
    overall_rating = property(get_overall_rating) 
admin.site.register(Rating) 

내가 포스트 그레스에 마이그레이션하기 위해 남쪽으로 이동을했고 이것이 내가 오류입니다 :

Error in migration: collect_data:0010_auto__chg_field_rating_tags__chg_field_rating_support__chg_field_ratin 
Traceback (most recent call last): 
    File "manage.py", line 15, in <module> 
    execute_from_command_line(sys.argv) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line 
    utility.execute() 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv 
    self.execute(*args, **options.__dict__) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute 
    output = self.handle(*args, **options) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/south/management/commands/migrate.py", line 108, in handle 
    ignore_ghosts = ignore_ghosts, 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/south/migration/__init__.py", line 213, in migrate_app 
    success = migrator.migrate_many(target, workplan, database) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/south/migration/migrators.py", line 235, in migrate_many 
    result = migrator.__class__.migrate_many(migrator, target, migrations, database) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/south/migration/migrators.py", line 310, in migrate_many 
    result = self.migrate(migration, database) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/south/migration/migrators.py", line 133, in migrate 
    result = self.run(migration) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/south/migration/migrators.py", line 107, in run 
    return self.run_migration(migration) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/south/migration/migrators.py", line 81, in run_migration 
    migration_function() 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/south/migration/migrators.py", line 57, in <lambda> 
    return (lambda: direction(orm)) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellow/jellow/apps/collect_data/migrations/0010_auto__chg_field_rating_tags__chg_field_rating_support__chg_field_ratin.py", line 13, in forwards 
    db.alter_column('collect_data_rating', 'tags', self.gf('django.db.models.fields.IntegerField')()) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/south/db/generic.py", line 44, in _cache_clear 
    return func(self, table, *args, **opts) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/south/db/generic.py", line 522, in alter_column 
    flatten(values), 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/south/db/generic.py", line 273, in execute 
    cursor.execute(sql, params) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/django/db/backends/util.py", line 40, in execute 
    return self.cursor.execute(sql, params) 
    File "/Users/narensathiya/Documents/Documents/Jellow/Jellow/jellowenv/lib/python2.7/site-packages/django/db/backends/postgresql_psycopg2/base.py", line 52, in execute 
    return self.cursor.execute(query, args) 
django.db.utils.DatabaseError: column "tags" cannot be cast to type integer 

어떤 도움이 많이 주시면 감사합니다 사전에 감사합니다!

+0

정수의 형태가 아닌 데이터베이스에서'tags' 열에서 이미 어떤 항목이를 ? –

+0

예, 있어야합니다. 일부 값을 문자로 저장했습니다. 해당 열을 삭제하고 다시 만들어야합니까? – Badi8beach

답변

17

당신이 당신의 데이터를 던져 행복하다, 당신이 열을 삭제할 수 있습니다 당신이 당신의 데이터를 유지하려면 새

을 작성, 당신도

A) 새 열을 제공해야 다른 이름 또는
B)는 전환시에 데이터를 저장하는 임시 열을 생성

그러면 마이그레이션의 시퀀스를 필요

  1. 새로운 (또는 임시) 열을 추가하는 스키마 이전
  2. 명시 적으로 데이터를 이동하는 데이터 이전. "A"-> 1)
  3. 아마도 스키마 마이그레이션 삭제 임시 열 당신은 "(컬럼 이름 : 정수)를 사용하여"추가해야
+0

쿨 (Cool) 전에 데이터 마이그레이션 작업을 마쳤습니다. – Badi8beach

1

이 오류를 제거합니다. 하지만이 경우 직접 쿼리를 사용해야합니다.

migrateEngine.execute ('표 테스트 testScore :: 정수 사용 열 testScore 유형 정수를 ALTER ALTER')