问题
I hoping that you can help me out. I currently have Django1.7 running on windows7/Java7/Jython2.7/Postgresql9.3/postgresql-9.3-1102.jdbc41.
I learned today that on Django 1.7 there is no reason to install the South package for migrations because 1.7 has makemigrations and migrate commands built in. But even so when I try to apply those commands in that order I am getting some sort of error. How can I resolve this error?
For more information on django migrations. Django 1.7 Migrations
For more details about django on jython and the database settings. postgresql on jython-django
My settings are:
DATABASES = {
'default': {
'ENGINE': 'doj.db.backends.postgresql',
'NAME': 'lwc',
'USER': 'lwc',
'PASSWORD': 'lwc',
'HOST': '127.0.0.1',
'PORT': '5432',
}
}
This is my models.py file and I am trying to add ip_address when I do the makemigrations and migrate commands.
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)
Here is the error that I get from running the migrate command:
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]
I ran sqlmigrate because I understand that this is the sql calls that it is suppose to attempt to run. And I am not a DBA, but they don't look right to me. Anybody out there know SQL for Postgresql really well?
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;
I tried running that command in the Postgresql Query tool and I got the following error:
ERROR: column "ABC" does not exist
********** Error **********
ERROR: column "ABC" does not exist
SQL state: 42703
So, then this looks like a bug with Django 1.7. Has anyone else had this issue? What is the correct SQL statement? How could I create a workaround or resolve this issue?
来源:https://stackoverflow.com/questions/25716496/why-am-i-getting-an-error-when-i-run-the-migrate-command-on-jython-django-1-7-h