我对本地版本的网站进行了一些更改,将模型推送到服务器并进行了makemigrations
(revampenv) sammy@samuel-pc:~/revamp$ python manage.py makemigrations gallery
Migrations for 'gallery':
0032_auto_20170829_0058.py:
- Create model Area
- Create model Color
- Create model ThumbnailCache
- Add field unique_key_string to image
- Alter field example on image
- Alter field timeline on image
工作正常,然后我尝试迁移,我收到此错误
(revampenv) sammy@samuel-pc:~/revamp$ python manage.py migrate
Operations to perform:
Apply all migrations: account, sessions, admin, auth, thumbnail, contenttypes, gallery
Running migrations:
Rendering model states... DONE
Applying gallery.0032_auto_20170829_0058...Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 92, in migrate
self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 123, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 62, in database_forwards
field,
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/db/backends/postgresql/schema.py", line 21, in add_field
super(DatabaseSchemaEditor, self).add_field(model, field)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 396, in add_field
self.execute(sql, params)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 110, in execute
cursor.execute(sql, params)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/home/sammy/revamp/revampenv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: must be owner of relation gallery_image
在数据库db下面有本地env的副本之前,我遇到过这个或类似的错误,但现在情况并非如此。
(注意)其他型号也失败了
(revampenv) sammy@samuel-pc:~/revamp$ python manage.py makemigrations account
Migrations for 'account':
0003_userprofile_bio.py:
- Add field bio to userprofile
(revampenv) sammy@samuel-pc:~/revamp$ python manage.py migrate
...
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: must be owner of relation account_userprofile
更新 试图编辑数据库所有者
postgres=# ALTER DATABASE color_db OWNER TO revamp;
ALTER DATABASE
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'color_db',
'USER': 'revamp',
'PASSWORD': 'xxx',
'HOST': 'localhost',
'PORT': '',
}
}
但仍然会返回相同的错误
(revampenv) sammy@samuel-pc:~/revamp$ python manage.py migrate
...
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: must be owner of relation account_userprofile
答案 0 :(得分:1)