我希望你能帮助我。我目前在Windows7 / Java7 / Jython2.7 / Postgresql9.3 / postgresql-9.3-1102.jdbc41上运行Django1.7。
我今天了解到,在Django 1.7上没有理由安装South软件包进行迁移,因为1.7有makemigrations和迁移内置的命令。但即便如此,当我尝试按顺序应用这些命令时,我得到某种错误。如何解决此错误?
有关django迁移的更多信息。 Django 1.7 Migrations
有关jython上的django和数据库设置的更多详细信息。 postgresql on jython-django
我的设置是:
DATABASES = {
'default': {
'ENGINE': 'doj.db.backends.postgresql',
'NAME': 'lwc',
'USER': 'lwc',
'PASSWORD': 'lwc',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
这是我的models.py文件,当我执行makemigrations和migrate命令时,我正在尝试添加ip_address。
from django.db import models
class Join(models.Model):
email = models.EmailField()
ip_address = models.CharField(max_length=120, null=True) #This is the new field
timestamp = models.DateTimeField(auto_now_add = True, auto_now=False)
updated = models.DateTimeField(auto_now_add = False, auto_now=True)
def __unicode__(self):
return "%s" %(self.email)
以下是运行migrate命令时出现的错误:
C:\Users\mike\workspace\lwc>jython manage.py migrate
←[36;1mOperations to perform:←[0m
←[1m Apply all migrations: ←[0madmin, sessions, joins, auth, contenttypes
←[36;1mRunning migrations:←[0m
Applying joins.0003_join_ip_address...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\core\mana
gement\__init__.py", line 385, in execute_from_command_line
utility.execute()
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\core\mana
gement\__init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\core\mana
gement\base.py", line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\core\mana
gement\base.py", line 338, in execute
output = self.handle(*args, **options)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\core\mana
gement\commands\migrate.py", line 160, in handle
executor.migrate(targets, plan, fake=options.get("fake", False))
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\db\migrat
ions\executor.py", line 63, in migrate
self.apply_migration(migration, fake=fake)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\db\migrat
ions\executor.py", line 97, in apply_migration
migration.apply(project_state, schema_editor)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\db\migrat
ions\migration.py", line 107, in apply
operation.database_forwards(self.app_label, schema_editor, project_state, ne
w_state)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\db\migrat
ions\operations\fields.py", line 35, in database_forwards
schema_editor.add_field(
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\db\backen
ds\schema.py", line 411, in add_field
self.execute(sql, params)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\db\backen
ds\schema.py", line 98, in execute
cursor.execute(sql, params)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\db\backen
ds\utils.py", line 81, in execute
return super(CursorDebugWrapper, self).execute(sql, params)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\db\backen
ds\utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\db\utils.
py", line 94, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "C:\jython2.7b2\Lib\site-packages\django-1.7c3-py2.7.egg\django\db\backen
ds\utils.py", line 65, in execute
return self.cursor.execute(sql, params)
File "C:\jython2.7b2\Lib\site-packages\django_jython-1.7.0b2-py2.7.egg\doj\db\
backends\__init__.py", line 180, in execute
self.cursor.execute(sql, params)
django.db.utils.Error: ERROR: could not determine data type of parameter $1 [SQL
Code: 0], [SQLState: 42P18]
我运行了sqlmigrate,因为我知道这是sql调用,它可能会尝试运行。我不是DBA,但他们看起来并不合适。那里的任何人都知道Postgresql的SQL真的很好吗?
C:\Users\mike\workspace\lwc>jython manage.py sqlmigrate joins 0002_join_ref_
id
BEGIN;
ALTER TABLE `joins_join` ADD COLUMN `ref_id` varchar(120) DEFAULT "ABC" NOT NULL
;
ALTER TABLE `joins_join` ALTER COLUMN `ref_id` DROP DEFAULT;
COMMIT;
我尝试在Postgresql查询工具中运行该命令,我收到以下错误:
ERROR: column "ABC" does not exist
********** Error **********
ERROR: column "ABC" does not exist
SQL state: 42703
所以,这看起来像是Django 1.7的一个bug。其他人遇到过这个问题吗?什么是正确的SQL语句?我如何创建变通方法或解决此问题?