所以我现在正在快速迭代一个django应用程序,我不断调整models.py.在一两天的编程和测试过程中,我生成了几十个迁移文件.有时候我真的撕开了架构并完全重新做了.这会导致迁移过程对默认值和空值等抱怨很多.如果可能的话,我只想抓住所有迁移的东西并重新开始迁移,因为我终于知道我在做什么了.到目前为止,我的方法如下:
__init__.py.DELETE FROM south_migrationhistory WHERE app_name='my_app';./manage.py makemigrations my_app- 这会0001_initial.py在我的迁移文件夹中生成一个文件../manage migrate my_app- 我希望这个命令重新构建我的所有表,但是它说:"没有要应用的迁移."是什么赋予了?
此外,south_migrationhistory数据库表现在仍然在播放,我已经转向南并已切换到Django 1.7?
谢谢.
django database-migration django-south django-1.7 django-migrations
当我更改help_text或verbose_name运行任何模型字段并运行时python manage.py makemigrations,它会检测到这些更改并创建新的迁移,例如0002_xxxx.py.
我正在使用PostgreSQL,我认为这些更改与我的数据库无关(我想知道这些更改是否存在相关的DBMS).
为什么Django会为此类更改生成迁移?有没有选择忽略它们?
我可以手动安全地删除0002_xxxx.py上次迁移(0001_initial.py)的更改0002_xxxx.py吗?
有没有办法自动更新以前的迁移?
在我的Rails 4应用程序中,我想将我的迁移文件折叠成一个大文件(类似于schema.rb),因为是时候做一些内务管理但是我不确定如何访问存储迁移数据的数据库中的表所以当我运行迁移时,我没有收到任何错误/冲突.
问题如何访问和删除存储迁移数据的表中的数据?
表'用户':
|id|name|address|post_code|deleted_at|created_at|
Run Code Online (Sandbox Code Playgroud)
我想在'id'和'deleted_at'之间添加列'phone_nr'
是否可以通过Laravel 4.1迁移?
根据这里的文档:https: //docs.djangoproject.com/en/1.8/topics/migrations/它说:
migrate, which is responsible for applying migrations, as well as unapplying and listing their status.
Run Code Online (Sandbox Code Playgroud)
和
makemigrations, which is responsible for creating new migrations based on the changes you have made to your models.
Run Code Online (Sandbox Code Playgroud)
据我所知,我先做
makemigrations
Run Code Online (Sandbox Code Playgroud)
创建迁移文件,然后执行
migrate
Run Code Online (Sandbox Code Playgroud)
实际应用迁移?
请注意,我刚刚开始我的Django项目,并将我的应用程序添加到我的"installed_apps"列表中.在那之后,我做到了
python manage.py runserver
Run Code Online (Sandbox Code Playgroud)
它说
You have unapplied migrations; your app may not work properly until they are applied. Run 'python manage.py migrate' to apply them.
Run Code Online (Sandbox Code Playgroud)
它没有提到任何关于运行makemigrations的内容.
当我在postgresql上的Rails应用程序中运行我的迁移时,我得到了以下通知
NOTICE: CREATE TABLE will create implicit sequence "notification_settings_id_seq" for serial column "notification_settings.id"
NOTICE: CREATE TABLE / PRIMARY KEY will create implicit index "notification_settings_pkey" for table "notification_settings"
Run Code Online (Sandbox Code Playgroud)
我的迁移文件包含088_create_notification_settings.rb
class CreateNotificationSettings < ActiveRecord::Migration
def self.up
create_table :notification_settings do |t|
t.integer :user_id
t.integer :notification_id
t.boolean :notification_on
t.boolean :outbound
end
end
def self.down
drop_table :notification_settings
end
end
Run Code Online (Sandbox Code Playgroud)
我想知道
这个通知意味着什么?
如何避免这种通知?
如果不避免,此类通知对应用程序的影响是什么?
问候,
萨里尔
我正在尝试使用带有SQLALchemy的参数(在一个alembic脚本中)运行这个简单的原始sql语句:
from alembic import op
t = {"code": "123", "description": "one two three"}
op.execute("insert into field_tags (id, field_id, code, description) "+
"values (1,'zasz', :code ,:description')", t)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
sqlalchemy.exc.StatementError: A value is required for bind parameter
'description' (original cause: InvalidRequestError: A value is required for
bind parameter 'description') "insert into field_tags (id, field_id, code,
description) values (1, 'math',
%(code)s ,%(description)s)" []
Run Code Online (Sandbox Code Playgroud)
解决方案:
t = {"code": "123", "description": "one two three"}
from sqlalchemy.sql import text
op.get_bind().execute(text("insert into field_tags (id, field_id, code, description) …Run Code Online (Sandbox Code Playgroud) python sqlalchemy database-migration flask-sqlalchemy alembic
我的表中有user_id fk列
$table->foreign('user_id')->references('id')->on('users');
Run Code Online (Sandbox Code Playgroud)
我应该在现有列上添加级联删除功能.我怎样才能做到这一点?
我正在尝试在具有父子关系的2个对象上使用复合主键.每当我尝试创建新的迁移时,都会收到错误消息:
无法确定类型"Models.UserProjectRole"的复合主键排序.使用ColumnAttribute或HasKey方法指定组合主键的顺序.
根据错误建议,我确实添加了注释,Column (Order = X)但错误仍然存在并且不会消失,除非我只留下一个带有Key注释的字段.以下是我的目标:
public class UserProjectRole
{
[Key, Column(Order = 0),DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid UserProjectRoleID { get; set; }
[Key, Column (Order = 1)]
public Guid ProjectID { get; set; }
[ForeignKey("ProjectID")]
public Project Project { get; set; }
public Guid AppUserGuid { get; set; }
// followed by a number of unrelated String fields.
}
Run Code Online (Sandbox Code Playgroud)
这是Project类:
public class Project: Base
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public Guid ProjectID { get; set; }
public virtual ICollection<UserProjectRole> UserRoles { …Run Code Online (Sandbox Code Playgroud) django如何知道迁移是否已经应用?它通常是正确的,但如果它没有,我不知道从哪里开始故障排除.
django ×4
python ×3
django-1.7 ×2
django-south ×2
laravel ×2
laravel-4 ×2
alembic ×1
c# ×1
django-1.9 ×1
php ×1
postgresql ×1
ruby ×1
sqlalchemy ×1