2010-07-01 38 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 文件,并且所有这些错误应该去 以外。

相关问题