我用 mysql2 启动了 Rails 应用程序。首先我要把它部署到便宜的服务器上。当用户增加时,我需要将它迁移到AWS或digitalocean。如何获取数据库备份并将其恢复到新的?
我有一个用户表。我正在尝试将列的默认整数值从 0 更改为 1。
到目前为止,我能想到的唯一方法是在单独的迁移中删除并添加具有更新的默认值的列。但我不想这样做,因为这会丢失预先存在的表中的数据。我一直无法在网上找到答案。
有 Sequel 方法可以做到这一点吗?
我是Cakephp的新手,并使用Cakephp3.3构建应用程序,我正在进行迁移,我必须创建一个user_infos表,并且想要添加一个新列user_id,我能够通过迁移添加新列但我不知道如何添加外键.
这是我的迁移文件
public function change()
{
$table = $this->table('user_infos');
$table->addColumn('user_id', 'integer', [
'default' => null,
'limit' => 11,
'null' => false,
]);
$table->addColumn('title', 'string', [
'default' => null,
'limit' => 255,
'null' => false,
]);
$table->addColumn('created', 'datetime', [
'default' => null,
'null' => false,
]);
$table->addColumn('modified', 'datetime', [
'default' => null,
'null' => false,
]);
$table->create();
}
Run Code Online (Sandbox Code Playgroud) 下面是我的代码请告诉我我错在哪里..
public function up(){
$this->dbforge->add_field(array(
'id'=> array(
'type' => 'int',
'constraint' => 11,
'auto_increment'=> TRUE,
),
'ip_address'=> array(
'type' => 'VARCHAR',
'constraint'=> '40',
),
'login'=> array(
'type' => 'VARCHAR',
'constraint'=> '50',
),
'time'=> array(
'type' => 'timestamp',
'Default' => 'CURRENT_TIMESTAMP',
'ON UPDATE CURRENT_TIMESTAMP' => TRUE,
),
));
$this->dbforge->add_key('id',TRUE);
$this->dbforge->create_table('login_attempts');
echo "table created";
}
Run Code Online (Sandbox Code Playgroud)
并且此错误将在运行迁移时生成
错误编号:
1067
“时间”的默认值无效
CREATE TABLE login_attempts (id int(11) NOT NULL AUTO_INCREMENT, ip_address VARCHAR(40) NOT NULL, login VARCHAR(50) NOT NULL, 时间时间戳 NOT NULL DEFAULT 'CURRENT_TIMESTAMP', CONSTRAINT pk_login_attempts …
在https://flywaydb.org/documentation/migration/repeatable引用 flyway 文档:
可重复迁移没有版本。相反,每次它们的校验和发生变化时都会(重新)应用它们。
这对于管理数据库对象非常有用,这些对象的定义可以简单地在版本控制中的单个文件中维护。
在单个迁移运行中,可重复的迁移总是最后应用,在所有挂起的版本化迁移都已执行之后。可重复迁移按其描述的顺序应用。
这听起来令人兴奋,但是我似乎无法找到有关这实际上是如何工作的以及如何初始化可重复迁移的任何说明。我知道对于版本化迁移,我可以创建一个基础迁移 ( https://flywaydb.org/documentation/existing ),然后运行基线命令为我的未来版本做好准备。但是对于可重复的迁移,我不明白 flyway 如何能够校验和更改。
相反,他们是
每次校验和更改时(重新)应用。
flyway 是否假设我正在从头开始重新创建我的数据库以使校验和比较正常工作?这将解释它如何能够比较校验和(因为它可以访问数据库中已有对象的文件定义)。
关于我的申请的一些背景:
问题:如果我运行命令migrations:diff从实体类中的更改生成迁移,则会出现以下异常:
[Doctrine\DBAL\DBALException] Unknown column type "json" requested.
Any Doctrine type that you use has to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the known types with \Doctrine\DBAL\Types\Type::getTypesMap().
Run Code Online (Sandbox Code Playgroud) 我在我的 django 项目中使用了两个数据库。为了处理我有一个路由器文件:
class SecondDB:
"""
A router to control all database operations on models in the
auth application.
"""
def db_for_read(self, model, **hints):
if model._meta.app_label == 'app_in_second_db':
return 'second_db'
else:
return 'default'
def db_for_write(self, model, **hints):
if model._meta.app_label == 'app_in_second_db':
return 'app_in_second_db'
else:
return 'default'
def allow_relation(self, obj1, obj2, **hints):
if obj1._meta.app_label == 'app_in_second_db' or \
obj2._meta.app_label == 'auditlog':
return True
else:
return False
def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label == 'app_in_second_db':
return db == 'second_db'
else: …Run Code Online (Sandbox Code Playgroud) 我正在尝试迁移我新创建的迁移。问题是等待迁移的一批迁移是按照我使用创建迁移的顺序
php artisan make:migration
Run Code Online (Sandbox Code Playgroud)
因此,我的product_list迁移试图在尚未迁移的表上设置外键。
$table->foreign('product_category')->references('id')->on('product_categories');
$table->foreign('product_type')->references('id')->on('product_types')->onDelete('cascade');
Run Code Online (Sandbox Code Playgroud)
当我运行时,php artisan migrate我收到这些错误:
C:\xampp\htdocs\iezonsolutions>php artisan migrate
Migrating: 2019_01_15_001617_product_list
Illuminate\Database\QueryException : SQLSTATE[HY000]: General error: 1005 Can't create table `iezonsolutions`.`#sql-1844_16e` (errno: 150 "Foreign key constraint is incorrectly formed") (SQL: alter table `product_list` add constraint `product_list_product_category_foreign` foreign key (`product_category`) references `product_categories` (`id`))
at C:\xampp\htdocs\iezonsolutions\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664
660| // If an exception occurs when attempting to run a query, we'll format the error
661| // message to include the bindings with SQL, which will make …Run Code Online (Sandbox Code Playgroud) 我正在 docker-compose 图像上运行一个 rails 应用程序。创建用户设计后,当我运行docker-compose run web rails db:migrate它时显示以下错误:PG::ConnectionBad: FATAL: could not open relation mapping file "global/pg_filenode.map": Permission denied
我已经尝试了所有与 rails 和 psql 相关的解决方案,所以我猜我的问题出在 docker-compose 程序上,我也尝试过,sudo但结果是一样的
代码:我运行的命令是docker-compose run web rails db:migrate在docker-compose run web rails g devise usuario
这是输出:
rails aborted!
PG::ConnectionBad: FATAL: could not open relation mapping file "global/pg_filenode.map": Permission denied
/usr/local/bundle/gems/pg-1.1.4/lib/pg.rb:56:in `initialize'
/usr/local/bundle/gems/pg-1.1.4/lib/pg.rb:56:in `new'
/usr/local/bundle/gems/pg-1.1.4/lib/pg.rb:56:in `connect'
Run Code Online (Sandbox Code Playgroud)
此链接中的其余日志:https : //hastebin.com/axiboxohem.bash
我需要在生产环境中为基于 Rocket 的应用程序运行 Diesel 数据库迁移。通常有几种方法可以为数据库执行迁移:
我更喜欢使用--migrate应用程序二进制文件的标志调用的第二个选项,但由于目标应用程序相当简单,第一种方法就可以了。
Diesel 问题跟踪器中有一个关于在生产中运行迁移的线程,并提供有关如何执行此操作的建议:
- 添加
diesel_migrations到您的依赖项- 包括
extern crate diesel_migrations在你的箱子,并确保与装饰它#[macro_use]- 在代码的开头,添加
embed_migrations!()- 要运行迁移,请使用
embedded_migrations::run(&db_conn)
在main.rs我做了:
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
extern crate rocket;
#[macro_use]
extern crate rocket_contrib;
#[database("my_db_name")]
pub struct DbConn(diesel::PgConnection);
fn main() {
// Update database
embed_migrations!();
embedded_migrations::run(&DbConn);
// Launch the app
...
}
Run Code Online (Sandbox Code Playgroud)
这导致错误:
#![feature(proc_macro_hygiene, decl_macro)]
#[macro_use]
extern crate diesel;
#[macro_use]
extern crate diesel_migrations;
#[macro_use]
extern …Run Code Online (Sandbox Code Playgroud) mysql ×2
php ×2
cakephp ×1
codeigniter ×1
database ×1
django ×1
doctrine-orm ×1
flyway ×1
laravel ×1
laravel-5 ×1
migration ×1
mysql2 ×1
phinx ×1
ruby ×1
rust ×1
rust-diesel ×1
rust-rocket ×1
sequel ×1
web-hosting ×1