🔍

首页Home › 开发工具Developer Tools

🧱 SQL 建表语句生成 Yii2 模型SQL CREATE TABLE to Yii2 Model

根据 MySQL 的 CREATE TABLE 语句生成 Yii2 ActiveRecord 模型类:包含 @property 注释、tableName()、按字段类型生成的 rules() 校验规则和来自字段注释的 attributeLabels()。Generate a Yii2 ActiveRecord model from a MySQL CREATE TABLE statement, with @property docs, tableName(), rules() derived from column types and attributeLabels() taken from column comments.

使用说明与常见问题How-to & FAQ

「SQL 建表语句生成 Yii2 模型」是什么?What is the SQL CREATE TABLE to Yii2 Model tool?

根据 MySQL 的 CREATE TABLE 语句生成 Yii2 ActiveRecord 模型类:包含 @property 注释、tableName()、按字段类型生成的 rules() 校验规则和来自字段注释的 attributeLabels()。Generate a Yii2 ActiveRecord model from a MySQL CREATE TABLE statement, with @property docs, tableName(), rules() derived from column types and attributeLabels() taken from column comments.

如何使用「SQL 建表语句生成 Yii2 模型」?How do I use the SQL CREATE TABLE to Yii2 Model?

粘贴 CREATE TABLE 语句,设置命名空间和表前缀,即可得到与 Gii 风格相近的模型代码。NOT NULL 且没有默认值的字段生成 required 规则,整数、数字、字符串长度、枚举值都会生成对应规则。Paste a CREATE TABLE statement and set the namespace and table prefix to get model code in a Gii-like style. NOT NULL columns without defaults become required; integers, numbers, string lengths and enum values get matching rules.

和 Gii 生成的有什么区别?How does it differ from Gii?

Gii 需要连接数据库读取表结构,这里只解析粘贴的 SQL,适合没有数据库连接或只拿到 DDL 的场景;外键关系(getXxx() 关联方法)和唯一索引规则需要自行补充。Gii connects to a database to read the schema; this tool only parses pasted SQL, which helps when you have just the DDL. Relations (getXxx() methods) and unique-index rules must be added by hand.

设置表前缀有什么用?What does the table prefix do?

如果表名带有前缀(如 tbl_user),填写 tbl_ 后类名会生成为 User,tableName() 返回 {{%user}},由 Yii 的 db 组件 tablePrefix 配置自动替换。If tables carry a prefix (e.g. tbl_user), entering tbl_ makes the class User and tableName() return {{%user}}, which Yii replaces using the db component’s tablePrefix.

「SQL 建表语句生成 Yii2 模型」免费吗?数据会上传吗?Is the SQL CREATE TABLE to Yii2 Model free? Is my data uploaded?

「SQL 建表语句生成 Yii2 模型」完全免费,无需注册或安装,手机和电脑都能用;所有处理都在你的浏览器本地完成,输入的内容和文件不会上传到服务器。The SQL CREATE TABLE to Yii2 Model is completely free with no sign-up or install and works on phones and desktops; everything runs locally in your browser and nothing you enter is uploaded.

相关工具Related tools

🧩 SQL 建表语句转 C# 实体类SQL CREATE TABLE to C# Class🗃️ SQL 建表语句转 Java 实体类SQL (CREATE TABLE) to Java Entity🐘 JSON 转 PHP 数组JSON to PHP Array🐘 PHP 序列化/反序列化PHP Serialize / Unserialize🗄️ SQL 格式化/压缩SQL Formatter & Minifier

← 全部工具All tools