我正在开发一个 Spring-MVC 应用程序,我们使用 etherpad 作为文本编辑器。Etherpad 将其内容作为简单的键值对保存在数据库中。但对于这样一个简单的任务来说,性能太差了,而且 Etherpad 不执行任何 JOIN 或其他复杂的操作。出于这个原因,我们决定迁移到redis。Redis 正在工作,但我们的数据滞留在 postgresql 数据库中。我们如何将其移动到 Redis 第一个数据库。这是数据库的样子:
Redis 在本地工作于端口 6379。
我有表“invoice_relations”,它是变形表。所以在迁移中我写道:
$table->morphs('invoice_relations');
但是它在运行迁移时出错,
语法错误或访问冲突:1059标识符呐
我'invoice_relations_invoice_relations_id_invoice_relations_type_index'过长在/ var / www / html等/ ST /销售密宗/供应商/教义/ DBAL /
lib中/教义/ DBAL /驱动器/ PDOStatement.php:105
我正在尝试在 Sequelize 中编写迁移并希望删除 defaultValue 约束。什么是正确的语法?我已经尝试了以下两种方法:
return queryInterface.removeConstraint('Table', 'table_columnName_default')
return queryInterface.removeConstraint('Table', 'columnName_default')
Run Code Online (Sandbox Code Playgroud) 我有一个任务,描述为“使用 Yii2 迁移创建新数据库,并默认使用它”。但我有一些勾结:我必须在我的main-local.php文件中设置至少一个默认数据库才能开始迁移。但我也必须通过初始迁移创建这个数据库。
return [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=default_base',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
];
Run Code Online (Sandbox Code Playgroud)
我该如何处理?创建一个带有迁移的数据库并设置为默认数据库。
当我执行迁移时(迁移文件中有代码):
public function safeUp()
{
$this->execute("CREATE DATABASE default_base");
}
Run Code Online (Sandbox Code Playgroud)
我有一个例外:
General error: 1007 Can't create database 'default_base'; database exists
Run Code Online (Sandbox Code Playgroud)
我意识到这是因为我已经在 phpmyadmin 中创建了 default_base(单击按钮“创建数据库”),并将其与我的main-local.php文件中的应用程序连接。但是我只需要在执行yii migrate.
UPD
我已经尝试了 rob006 推荐的方式,但出现连接错误
Exception 'yii\db\Exception' with message 'SQLSTATE[HY000] [1049] Unknown database 'default_base''
Run Code Online (Sandbox Code Playgroud)
我的 main-local.php 看起来就像 rob006 推荐的那样,但我仍然无法迁移。仅当我设置时才有效:
'preinstallDb' => [
'class' => 'yii\db\Connection', …Run Code Online (Sandbox Code Playgroud) 我正在使用 Laravel 8。我正在尝试创建一个新表,但该表在数据库中不存在,并且没有任何其他同名表。我进行了迁移,这是迁移代码:
\n<?php\n\nuse Illuminate\\Database\\Migrations\\Migration;\nuse Illuminate\\Database\\Schema\\Blueprint;\nuse Illuminate\\Support\\Facades\\Schema;\n\nclass CreateCertificateTable extends Migration\n{\n /**\n * Run the migrations.\n *\n * @return void\n */\n public function up()\n {\n Schema::table('certificate', function (Blueprint $table) {\n $table->id();\n $table->unsignedBigInteger('user_id');\n $table->unsignedBigInteger('vac_id');\n $table->time('last_shot_date');\n $table->timestamps();\n\n $table->foreign('user_id')->references('id')->on('users');\n $table->foreign('vac_id')->references('id')->on('vaccination');\n });\n }\n\n /**\n * Reverse the migrations.\n *\n * @return void\n */\n public function down()\n {\n Schema::table('certificate', function (Blueprint $table) {\n //\n });\n }\n}\n\nRun Code Online (Sandbox Code Playgroud)\n做完之后
\nphp artisan migrate\nRun Code Online (Sandbox Code Playgroud)\n这是我收到的完整错误消息:
\n Illuminate\\Database\\QueryException\n\n SQLSTATE[42S02]: Base table or view not found: 1146 Table …Run Code Online (Sandbox Code Playgroud) 运行“php artisan migrate:fresh”命令时,它显示 SQLSTATE[42000] 错误
这是完整的错误消息
SQLSTATE[42000]:语法错误或访问冲突:1064 你的 SQL 语法有错误;检查手册对应到你的MySQL服务器版本正确的语法使用近“无符号不为空,created_at时间戳无效,updated_at时间戳空)DEF”位于第1行(SQL:CREATE TABLE products(idBIGINT的无符号NOT NULL的auto_increment主键,name为varchar(191 ) not null, descriptionvarchar(1000) not null, quantityint unsigned not null, statusvarchar(191) not null 默认'unavailable', imagevarchar(191) not null 默认'unavailable', seller_idvarchar(191) unsigned not null, created_attimestamp null, updated_attimestamp null) 默认字符集 utf8mb4 collate 'utf8mb4_unicode_ci')
这是迁移 Product::UNAVAILABLE_PRODUCT 在 Product 模型中定义为“unavailabel”
public function up()
{
Schema::create('products', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('description',1000);
$table->integer('quantity')->unsigned();
$table->string('status',)->default(Product::UNAVAILABLE_PRODUCT);
$table->string('image',)->default(Product::UNAVAILABLE_PRODUCT);
$table->string('seller_id',)->unsigned(); …Run Code Online (Sandbox Code Playgroud) 刚刚创建了一个新的 laravel 项目并尝试迁移表,我得到了这个:
SQLSTATE[HY000] [2002] 没有这样的文件或目录(SQL:select * from information_schema.tables where table_schema = SugarDaddy and table_name = migrations and table_type = 'BASE TABLE')
我尝试清除缓存、路由、配置,并将 DBHOST 从 127.0.0.1 更改为 localhost,然后再更改回来,正如我在几篇相关文章中看到的那样,但没有任何效果。我将把迁移和 ss 留在数据库中。
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/ …Run Code Online (Sandbox Code Playgroud) 我有适用于 API 和 MySQL 数据库的 Dockerfile,它应该执行迁移:
FROM node
WORKDIR /api
COPY . .
RUN npm install
EXPOSE 3001
VOLUME [ "/api/node_modules" ]
CMD [ "npm", "start" ]
Run Code Online (Sandbox Code Playgroud)
另外,还有一个 docker-compose 文件,其中我将数据库作为服务:
db:
image: mysql
container_name: database
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: password
MYSQL_PASSWORD: password
MYSQL_DATABASE: testdb
Run Code Online (Sandbox Code Playgroud)
问题是,我不知道如何运行迁移。我应该从 docker-compose 文件还是 Dockerfile 中执行此操作?
我试图在 Dockerfile 中做类似的事情,但它似乎不起作用:
...
CMD [ "knex", "migrate:latest" ]
...
Run Code Online (Sandbox Code Playgroud)
或者:
...
RUN knex migrate:latest
...
Run Code Online (Sandbox Code Playgroud) 所以我有一个应用程序,它目前将数据存储在apache服务器和mysql上.我想迁移到firebase但我有以下问题:
我的数据是一个Business表,每个用户都存储了他们的数据.这包括他们的电子邮件和他们的业务的所有数据(地址,城市,商业名称等)我已经在json中导出数据并将其导入firebase,但现在我希望用户创建一个新的配置文件(在firebase中)然后"声称"他们的数据.
这应该是为了在用户和业务之间建立关系.
有关如何做到这一点的任何想法?
编辑:
所以问题是我将业务和我的用户放在一个对象或表中,如下所示:
{
"user_type": "Hotel",
"state": "Lakonia",
"postcode": "23100",
"city": "Mystras",
"country": "Greece",
"id": 1,
"num_of_rooms": "5",
"email": "info@email.com",
"address": "Something",
"time_of_register": "",
"name": "My hotel",
"latlng": ""
}
Run Code Online (Sandbox Code Playgroud)
为了将其迁移到Firebase,我创建了一个检查,因此当用户登录时,系统会运行查询,如果用户注册电子邮件与其中一个企业相同,我会将其移动到新的firebase数据集,注册用户唯一的密钥.因此,我没有两套,一套用于我的用户,另一套用于商业信息.