我是数据库迁移世界的新手。我在Rails和Laravel中使用或尝试使用迁移,但是没有一个我不理解这些部分:
1.对于数据库的每次修改,如添加列,将字段类型从整数更改为字符串,如果我从命令行生成迁移,请在Myisam中从InnoDB更改数据库类型?
//loadingAlert is a UIAlertController declared in the .h file
//present the Alert
loadingAlert = [UIAlertController alertControllerWithTitle:@"Loading..." message:@"Please wait while we fetch locations" preferredStyle:UIAlertControllerStyleAlert];
[self presentViewController:loadingAlert animated:YES completion:nil];
//parse JSON file
_listOfAcquisitions = nil;
MNSHOW_NETWORK_ACTIVITY(YES);
NSString *WebServiceURL = [NSString stringWithFormat:@"JSON URL", _search];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue, ^{
NSDictionary *dictionary = [JSONHelper loadJSONDataFromURL:WebServiceURL];
dispatch_async(dispatch_get_main_queue(), ^{
_listOfAcquisitions = [NSMutableArray array];
for (NSDictionary *oneEntry in dictionary) {
Acquisitions *acqu = [[Acquisitions alloc] init];
if([oneEntry objectForKey:@"ADDRESS1"] == (NSString *)[NSNull null]){acqu.ADDRESS1 = @"";}
else {acqu.ADDRESS1 = [oneEntry objectForKey:@"ADDRESS1"];}
if([oneEntry objectForKey:@"STATEABBR"] == (NSString *)[NSNull null]){acqu.STATEABBR = @"";}
else {acqu.STATEABBR = [oneEntry objectForKey:@"STATEABBR"];}
if([oneEntry objectForKey:@"TOWN"] == (NSString *)[NSNull null]){acqu.TOWN = @"";}
else {acqu.TOWN = [oneEntry objectForKey:@"TOWN"];}
if([oneEntry objectForKey:@"ZIPCODE"] == (NSString *)[NSNull null]){acqu.ZIPCODE = @"";}
else {acqu.ZIPCODE = [oneEntry objectForKey:@"ZIPCODE"];}
[_listOfAcquisitions addObject:acqu];
}
dispatch_async(dispatch_get_main_queue(), ^{
MNSHOW_NETWORK_ACTIVITY(NO);
[self refreshAnnotations:self];
});
});
});
//finally dismiss the alert...
[loadingAlert dismissViewControllerAnimated:YES completion:nil];
}
或者编辑现有的迁移文件以及执行迁移后?或手动创建文件?
2.当Laravel文件说:
要重命名列,可以在Schema上使用renameColumn方法 建设者。在重命名列之前,请务必添加doctrine / dbal 依赖于您的composer.json文件:
php artisan make:migration ........ for laravel
rake db:migration ..... for rails
这是否意味着我必须将此代码插入上一个迁移文件或创建新的迁移文件?
答案 0 :(得分:0)
最常见的做法是为更改生成新的迁移。比较工作流程:
创建新迁移时:
编辑现有内容时:
此外,当您在团队中工作时,每个成员也应该处理这些步骤。噪音太大,更好地产生新的迁移。