Skip to main content

Prisma 工作室

Prisma Studio 是一个独立的数据库可视化编辑器,允许你直接在浏览器中查看和操作数据。Prisma 7 引入了一个全新的独立 Studio,它从底层构建,无论是否使用 Prisma ORM,都能在各种环境下运行。

¥Prisma Studio is a standalone visual database editor that lets you view and manipulate data directly in your browser. Prisma 7 introduces a brand new standalone Studio, built from the ground up to work everywhere, with or without Prisma ORM.

与之前的版本不同,新的 Prisma Studio 由 SQL 驱动,完全不依赖于 Prisma 模式文件。它会直接检查你的数据库以了解其模式结构。这意味着你可以将其与任何受支持的数据库一起使用,而无需 Prisma schema 或项目。

¥Unlike previous versions, the new Prisma Studio is SQL-driven and does not rely on the Prisma schema file at all. Instead, it introspects your database directly to understand the schema structure. This means you can use it with any supported database without needing a Prisma schema or project.

请注意,Prisma Studio 不是开源的,但你仍然可以在 prisma/studio 存储库中创建问题。所有 "旧版 Studio" 相关问题均已关闭,因为之前的版本将不再进行任何维护。

¥Note that Prisma Studio is not open source but you can still create issues in the prisma/studio repo. All "old Studio" issues are being closed as there won't be any further work on the previous version.

先决条件

¥Prerequisites

Prisma Studio 是一个独立的工具,只需要一个数据库连接。你有两种选择:

¥Prisma Studio is a standalone tool that only requires a database connection. You have two options:

选项 1:与任何数据库结合使用(无需 Prisma 项目)

¥Option 1: Use with any database (no Prisma project required)

使用 --url 标志直接连接到任何受支持的数据库:

¥Connect directly to any supported database using the --url flag:

npx prisma studio --url="postgresql://user:password@localhost:5432/dbname"

这种方法无需任何 Prisma ORM 设置 - Studio 将直接检查你的数据库架构。

¥This approach works without any Prisma ORM setup—Studio will introspect your database schema directly.

选项 2:与 Prisma ORM 项目结合使用

¥Option 2: Use with a Prisma ORM project

如果你有一个现有的 Prisma 项目,Studio 可以读取你的数据库连接配置:

¥If you have an existing Prisma project, Studio can read your database connection configuration:

  • 包含数据库连接详细信息的 prisma.config.ts 配置文件

    ¥A prisma.config.ts configuration file with database connection details

  • 已配置的数据库连接

    ¥A configured database connection

注意

新版 Studio 不会读取 prisma/schema.prisma 文件。它会直接检查你的数据库以了解其模式结构。

¥The new Studio does not read the prisma/schema.prisma file. It introspects your database directly to understand the schema structure.

入门

¥Getting started

独立使用(不使用 Prisma ORM)

¥Standalone usage (without Prisma ORM)

要使用任何数据库启动 Prisma Studio,请提供连接 URL:

¥To launch Prisma Studio with any database, provide a connection URL:

npx prisma studio --url="postgresql://user:password@localhost:5432/dbname"

使用 Prisma ORM 项目

¥With a Prisma ORM project

如果你有一个 Prisma 项目,请在项目目录中运行以下命令:

¥If you have a Prisma project, run the following command in your project directory:

npx prisma studio --config ./prisma.config.ts

这两个命令都会启动一个本地 Web 服务器(默认端口 5555),并在浏览器中打开 Prisma Studio。Studio 直接连接到你的数据库并实时检查模式,从而为你的数据提供可视化界面 - 无需 Prisma 模式文件。

¥Both commands start a local web server (default port 5555) and open Prisma Studio in your browser. Studio connects directly to your database and introspects the schema in real-time to provide a visual interface for your data—no Prisma schema file required.

核心功能

¥Core features

Prisma Studio 提供以下几个用于操作数据库的关键功能:

¥Prisma Studio provides several key capabilities for working with your database:

浏览你的数据

¥Browse your data

Studio 在侧边栏中显示数据库中的所有表。选择任意表以表格格式查看其数据。你可以在不同的选项卡中打开多个表,以便同时处理相关数据。

¥Studio displays all tables from your database in a sidebar. Select any table to view its data in a table format. You can open multiple tables in separate tabs to work with related data simultaneously.

查看和编辑记录

¥View and edit records

你可以通过两种方式编辑数据:

¥You can edit data in two ways:

  • 内联编辑:双击任意单元格即可直接在表格中编辑其值

    ¥Inline editing: Double-click any cell to edit its value directly in the table

  • 侧边栏编辑:点击记录旁边的编辑图标,打开包含所有字段的详细视图。

    ¥Side panel editing: Click the edit icon next to a record to open a detailed view with all fields

更改会累积,必须使用保存按钮显式保存。它允许你在将更改提交到数据库之前进行多次编辑。

¥Changes are accumulated and must be saved explicitly using the save button. This lets you make multiple edits before committing them to the database.

添加新记录

¥Add new records

单击 "添加记录" 按钮创建新记录。Studio 根据每个字段的数据类型提供相应的输入控件:

¥Create new records by clicking the "Add record" button. Studio provides appropriate input controls based on each field's data type:

  • 用于字符串的文本字段

    ¥Text fields for strings

  • 用于输入整数和小数的数字输入

    ¥Number inputs for integers and decimals

  • 日期时间字段的日期选择器

    ¥Date pickers for datetime fields

  • 用于枚举和布尔值的下拉菜单

    ¥Dropdowns for enums and boolean values

  • 外键的关系选择器

    ¥Relation selectors for foreign keys

删除记录

¥Delete records

使用复选框选择一个或多个记录,然后单击“删除”按钮。删除操作需要确认,并立即生效(无法与其他更改一起批量处理)。

¥Select one or more records using the checkboxes and click the delete button. Deletions require confirmation and are applied immediately (they cannot be batched with other changes).

筛选和搜索

¥Filter and search

使用“筛选器”菜单缩小数据范围:

¥Use the Filters menu to narrow down your data:

  • 使用比较运算符(等于、大于、小于等)添加条件。

    ¥Add conditions using comparison operators (equals, greater than, less than, etc.)

  • 使用 AND 逻辑组合多个过滤器。

    ¥Combine multiple filters with AND logic

  • 清除单个筛选条件或一次性清除所有筛选条件

    ¥Clear individual filters or all filters at once

控制可见性

¥Control visibility

自定义视图:

¥Customize your view:

  • 字段菜单:显示或隐藏特定列

    ¥Fields menu: Show or hide specific columns

  • 显示菜单:使用 "获取"(limit)和 "跳过"(offset)选项控制分页

    ¥Showing menu: Control pagination with "Take" (limit) and "Skip" (offset) options

对数据进行排序

¥Sort data

点击任意列标题按该字段排序。再次点击可在升序和降序之间切换。

¥Click any column header to sort by that field. Click again to toggle between ascending and descending order.

快捷键

¥Keyboard shortcuts

Studio 支持常用操作的键盘快捷键。按 Cmd+/(macOS)或 Ctrl+/(Windows)查看所有可用快捷键。

¥Studio supports keyboard shortcuts for common operations. Press Cmd+/ (macOS) or Ctrl+/ (Windows) to view all available shortcuts.

理解数据类型

¥Understanding data types

Studio 为数据库中不同的字段类型显示可视化指示器:

¥Studio displays visual indicators for different field types in your database:

  • 文本字段:字符串值

    ¥Text fields: String values

  • 字段数量:整数和小数

    ¥Number fields: Integers and decimals

  • 日期/时间字段:时间戳和日期

    ¥Date/time fields: Timestamps and dates

  • 布尔字段:真/假值

    ¥Boolean fields: True/false values

  • 枚举字段:预定义选项列表

    ¥Enum fields: Predefined list of options

  • 关联字段:对其他表中记录的引用(外键)

    ¥Relation fields: References to records in other tables (foreign keys)

  • JSON 字段:结构化 JSON 数据

    ¥JSON fields: Structured JSON data

这些视觉提示可帮助你快速了解数据结构,因为 Studio 会直接从数据库中进行内省。

¥These visual cues help you quickly understand your data structure as Studio introspects it directly from your database.

Prisma 支持的数据库 Studio

¥Databases supported by Prisma Studio

Prisma Studio 目前支持以下数据库:PostgreSQL、MySQL 和 SQLite。

¥Prisma Studio currently supports the following databases: PostgreSQL, MySQL, and SQLite.

Prisma Studio 的 SQLite 要求

¥SQLite requirements for Prisma Studio

  • 目前,SQLite 数据库 URL 中的文件路径必须包含 file: 协议

    ¥File paths must have a file: protocol right now in the database url for SQLite

  • Node.js 22.5+:与内置的 node:sqlite 模块即插即用

    ¥Node.js 22.5+: Works out of the box with the built-in node:sqlite module

    • 可能需要 NODE_OPTIONS=--experimental-sqlite 环境变量

      ¥May require NODE_OPTIONS=--experimental-sqlite environment variable

  • Node.js 20:需要安装 better-sqlite3 作为依赖。

    ¥Node.js 20: Requires installing better-sqlite3 as a dependency

  • Deno >= 2.2:通过 内置 SQLite 模块 支持

    ¥Deno >= 2.2: Supported via built-in SQLite module

  • Bun:Prisma Studio 与 SQLite 的支持即将推出,目前尚未提供。

    ¥Bun: Support for Prisma Studio with SQLite is coming soon and is not available yet

:::tipnpx with better-sqlite3][使用

如果你的运行时环境中没有 node:sqlite,或者你不想将 better-sqlite3 作为硬性依赖安装(它会增加约 10MB 的空间),你可以使用 npx 临时安装所需的软件包:

¥If you don't have node:sqlite available in your runtime or prefer not to install better-sqlite3 as a hard dependency (it adds ~10MB), you can use npx to temporarily install the required packages:

npx -p better-sqlite3 -p prisma prisma studio --url file:./my_file.db

这个命令:

¥This command:

  • 临时安装 better-sqlite3,但不将其添加到项目依赖中

    ¥Temporarily installs better-sqlite3 without adding it to your project dependencies

  • 使用指定的 SQLite 数据库文件运行 Prisma Studio

    ¥Runs Prisma Studio with the specified SQLite database file

  • 避免 better-sqlite3 在你的项目中占用 10MB 的额外资源

    ¥Avoids the 10MB overhead of better-sqlite3 in your project

:::

尚未支持的数据库

¥Databases not yet supported

目前尚不支持 CockroachDB 和 MongoDB,但未来版本可能会添加。如果你使用的是以下数据库:

¥Support for CockroachDB and MongoDB is not currently available but may be added in future releases. If you're using these databases:

故障排除

¥Troubleshooting

PostgreSQL:"无法识别的配置参数 'schema'" 错误

¥PostgreSQL: "unrecognized configuration parameter 'schema'" error

连接到 PostgreSQL 数据库时,如果你的连接字符串包含 schema 查询参数,则可能会遇到以下错误:

¥When connecting to PostgreSQL databases, you may encounter this error if your connection string includes the schema query parameter:

unrecognized configuration parameter "schema"

这是因为新的 Studio 是独立的,它会将你的连接 URL 直接传递给 PostgreSQL 驱动程序,而无需任何处理。你提供的 URL(无论是通过 prisma.config.ts 还是 --url 标志)都必须是有效的 PostgreSQL 连接字符串,且仅使用 标准 PostgreSQL 连接参数

¥This happens because the new Studio is standalone and passes your connection URL directly to the PostgreSQL driver without any processing. The URL you provide—whether via prisma.config.ts or the --url flag—must be a valid PostgreSQL connection string that only uses standard PostgreSQL connection parameters.

schema 参数是 Prisma ORM 的一个自定义参数,在 v6 及更早版本中有效,但 PostgreSQL 本身无法识别它。

¥The schema parameter was a custom Prisma ORM parameter that worked in v6 and earlier, but PostgreSQL itself doesn't recognize it.

要解决此问题,请改用标准的 search_path 参数:

¥To resolve this issue, use the standard search_path parameter instead:

# ❌ This will cause an error
postgresql://user:password@host:port/database?schema=my_schema

# ✅ Use this instead
postgresql://user:password@host:port/database?options=-c%20search_path%3Dmy_schema

或者,如果你使用的是默认的 public 模式,则可以完全删除 schema 参数,因为 PostgreSQL 会自动使用它。

¥Alternatively, you can remove the schema parameter entirely if you're using the default public schema, as PostgreSQL defaults to it automatically.

更多详情,请参阅相关的 GitHub 问题

¥For more details, see the related GitHub issue.

终端:无法运行脚本/Prisma 客户端请求出错

¥Terminal: Failed to run script / Error in Prisma Client request

缓存问题可能会导致 Prisma Studio 使用旧版本的查询引擎。你可能会看到以下错误:

¥Caching issues may cause Prisma Studio to use an older version of the query engine. You may see the following error:

Error in request:  PrismaClientKnownRequestError: Failed to validate the query Error occurred during query validation & transformation

要解决此问题,请删除以下文件夹:

¥To resolve, delete the following folders:

  • macOS 和 Linux 上的 ~/.cache/prisma

    ¥~/.cache/prisma on macOS and Linux

  • Windows 上的 %AppData%/Prisma/Studio

    ¥%AppData%/Prisma/Studio on Windows