2010-07-01 15 views
2

我有新的python和django我創建輪詢應用程序,並在創建模型輪詢和選擇使用「南」後在該應用程序。我想將問題字段的長度從200更改爲300,但即使使用南方語言,我也無法實現它。如何在Django中更新列數據類型

我已經運行了python manage.py schemamigration polls --initial命令來創建遷移文件,然後我在輪詢問題字段((question = models.CharField(max_length = 250))中進行更改,將max_length從200更改爲250。

並再次運行python manage.py schemamigration polls --auto這將生成新的遷移文件。之後

我運行python manage.py遷移民意調查,它顯示了以下錯誤的所有東西:

C:\Python26\lib\site-packages\MySQLdb\__init__.py:34: DeprecationWarning: the sets module is deprecated 
    from sets import ImmutableSet 
Running migrations for polls: 
- Migrating forwards to 0003_auto__chg_field_poll_question. 
> polls:0003_auto__chg_field_poll_question 
! Error found during real run of migration! Aborting. 

! Since you have a database that does not support running 
! schema-altering statements in transactions, we have had 
! to leave it in an interim state between migrations. 

! You *might* be able to recover with: = ALTER TABLE `polls_poll` ; [] 
    = ALTER TABLE `polls_poll` MODIFY `question` varchar(200) NOT NULL;; [] 
    = ALTER TABLE `polls_poll` ALTER COLUMN `question` DROP DEFAULT; [] 

! The South developers regret this has happened, and would 
! like to gently persuade you to consider a slightly 
! easier-to-deal-with DBMS. 
! NOTE: The error which caused the migration to fail is further up. 
Traceback (most recent call last): 
    File "manage.py", line 11, in <module> 
    execute_manager(settings) 
    File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 
362, in execute_manager 
    utility.execute() 
    File "C:\Python26\lib\site-packages\django\core\management\__init__.py", line 
303, in execute 
    self.fetch_command(subcommand).run_from_argv(self.argv) 
    File "C:\Python26\lib\site-packages\django\core\management\base.py", line 195, 
in run_from_argv 
    self.execute(*args, **options.__dict__) 
    File "C:\Python26\lib\site-packages\django\core\management\base.py", line 222, 
in execute 
    output = self.handle(*args, **options) 
    File "C:\Python26\lib\site-packages\south\management\commands\migrate.py", lin 
e 109, in handle 
    ignore_ghosts = ignore_ghosts, 
    File "C:\Python26\lib\site-packages\south\migration\__init__.py", line 202, in 
migrate_app 
    success = migrator.migrate_many(target, workplan, database) 
    File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 220, i 
n migrate_many 
    result = migrator.__class__.migrate_many(migrator, target, migrations, datab 
ase) 
    File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 291, i 
n migrate_many 
    result = self.migrate(migration, database) 
    File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 125, i 
n migrate 
    result = self.run(migration) 
    File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 99, in 
run 
    return self.run_migration(migration) 
    File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 81, in 
run_migration 
    migration_function() 
    File "C:\Python26\lib\site-packages\south\migration\migrators.py", line 57, in 
<lambda> 
    return (lambda: direction(orm)) 
    File "C:\mysite\..\mysite\polls\migrations\0003_auto__chg_field_poll_question. 
py", line 12, in forwards 
    db.alter_column('polls_poll', 'question', self.gf('django.db.models.fields.C 
harField')(max_length=250)) 
    File "C:\Python26\lib\site-packages\south\db\generic.py", line 330, in alter_c 
olumn 
    self.delete_foreign_key(table_name, name) 
    File "C:\Python26\lib\site-packages\south\db\generic.py", line 588, in delete_ 
foreign_key 
    constraints = list(self._constraints_affecting_columns(table_name, [column], 
"FOREIGN KEY")) 
    File "C:\Python26\lib\site-packages\south\db\mysql.py", line 140, in _constrai 
nts_affecting_columns 
    """, [db_name, table_name, type]) 
    File "C:\Python26\lib\site-packages\south\db\generic.py", line 134, in execute 

    cursor.execute(sql, params) 
    File "C:\Python26\lib\site-packages\django\db\backends\util.py", line 19, in e 
xecute 
    return self.cursor.execute(sql, params) 
    File "C:\Python26\lib\site-packages\django\db\backends\mysql\base.py", line 84 
, in execute 
    return self.cursor.execute(query, args) 
    File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 168, in execute 
    if not self._defer_warnings: self._warning_check() 
    File "C:\Python26\lib\site-packages\MySQLdb\cursors.py", line 82, in _warning_ 
check 
    warn(w[-1], self.Warning, 3) 
_mysql_exceptions.Warning: Can't find file: 'slow_log' (errno: 2) 

請幫我

0003的樣子:

類移民(SchemaMigration):

def forwards(self, orm): 

    # Changing field 'Poll.question' 
    db.alter_column('polls_poll', 'question', self.gf('django.db.models.fields.CharField')(max_length=250)) 


def backwards(self, orm): 

    # Changing field 'Poll.question' 
    db.alter_column('polls_poll', 'question', self.gf('django.db.models.fields.CharField')(max_length=200)) 

Ansh J

+0

您正在使用哪個數據庫? 0003遷移是怎樣的?你申請了0001和0002嗎? – googletorp 2010-07-01 12:40:51

+0

是既可以正常工作。 – 2010-07-01 12:55:32

回答

1

爲了能夠回答有把握這個問題,你需要表現出遷移在0002和0003 ...

然而,在我看來,由此導致的異常僅僅是與MySQL的問題(它無法找到它的'慢日誌'),它會創建一條傳播到南部的警告,該警告會跳過它。

+1

這是一個數據庫錯誤,與遷移無關。 – Evgeny 2011-09-11 16:47:39

2

請從mysql控制檯中修改mysql表!

python manage.py dbshell 
alter table appname_modelname modify `question` varchar(200) NOT NULL; 
+1

這是直接更改數據庫中的表的方法。我想通過南達到它,因爲它建議如果我嘗試在任何時間添加一列... 希望你明白... – 2010-07-01 12:30:32

1

你遇到的問題不在Django或South,它在MySQL中。 MySQL是咳嗽起來有以下:

_mysql_exceptions.Warning: Can't find file: 'slow_log' (errno: 2) 

,它的恐慌的MySQLdb的圖書館,這是觸發救市,儘管這只是一個警告。

你需要找出MySQL爲什麼如此關心其丟失的slow_log文件。

0

我懷疑你可能在 mysql數據庫目錄下有general_log和slow_log frm文件,沒有任何對應的數據文件。如果 是這種情況,那麼只需從mysql數據庫目錄中'rm'general_log.frm和slow_log.frm 文件,並且所有這些錯誤應該去 以外。

相關問題