简体   繁体   English

如果我在 MySQL 中有设计的数据库,是否需要创建数据库迁移?

[英]Do I need to create DB migration, if I have a designed DB in MySQL?

I designed a database in MYSQL.我在 MYSQL 中设计了一个数据库。 Now I want to connect that with my Laravel application.现在我想将它与我的 Laravel 应用程序连接起来。 But after researching, I understand that I need to migrate the database into Laravel by creating migration tables.但是经过研究,我知道我需要通过创建迁移表将数据库迁移到Laravel。 But doing the same thing that I did in MySQL is tedious.但是做我在 MySQL 做的同样的事情是乏味的。 I think there is another way to do the stuff.我认为还有另一种方法可以做这些事情。 After searching I got this article from stackoverflow, but this is related to yii framework.搜索后我从stackoverflow得到了这篇文章,但这与yii框架有关。 I think someone knows here the solution of my problem.我想有人知道我的问题的解决方案。

I don't see a problem here, you can just connect Laravel to your DB (by editing your.env file) without any problems, migration files are just an easier way to design and implement your tables (also altering your tables' scheme on production is a very useful usage for migrations), but with that being done then no further actions required, and you are good to go!我在这里没有看到问题,您可以将 Laravel 连接到您的数据库(通过编辑 your.env 文件),没有任何问题,迁移文件只是设计和实现表的更简单方法(也可以在生产对于迁移来说是一个非常有用的用法),但是完成之后就不需要进一步的操作了,你就可以开始了!

it's pretty obvious, you can update the database setting in the.env file and use DB::table('your_table_name') and get whatever query you want.很明显,您可以更新 .env 文件中的数据库设置并使用 DB::table('your_table_name') 并获取您想要的任何查询。

If you have created database and also tables, you don't need to create migration.如果您已经创建了数据库和表,则不需要创建迁移。 Actually migration is because you can create tables more fast with migrations实际上迁移是因为您可以通过迁移更快地创建表

The upside of using migrations is that the exact same database can be created on different systems (ex: co-workers or acceptance/production servers).使用迁移的好处是可以在不同的系统上创建完全相同的数据库(例如:同事或验收/生产服务器)。

Laravel migrations have an up and a down function so you can rollback to a specific version if something went wrong, very usefull when publishing your code. Laravel 迁移具有updown function 因此如果出现问题,您可以回滚到特定版本,这在发布代码时非常有用。

That being said, co-workers could also review the database changes and for example hint at using more indexes and foreign keys.话虽如此,同事也可以查看数据库更改,例如提示使用更多索引和外键。

As the other comments said, it's not a requirement you use migrations but it has considerable advantages versus creating and updating the database manually.正如其他评论所说,这不是您使用迁移的要求,但与手动创建和更新数据库相比,它具有相当大的优势。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我需要规范化此MySQL数据库吗? - Do I need to normalize this MySQL db? 为什么我必须运行两次迁移才能使值出现在数据库中? - Why do I have to run migration twice for values to appear in DB? 如果我将一个进程分解为ruby,我是否需要重新连接到Mysql DB? - If I Fork a process in ruby, do I need to reconnect to Mysql DB? 在MySQL DB中,如何创建插入此类数据的循环? - In MySQL DB, how do I create a loop to insert such data? 我需要从 mysql 存储过程连接到 Access 数据库,以更新我已经在 mysql db 中创建的表 - I need connection to an Access Database from a mysql stored procedure to update tables i already create in mysql db MySQL数据库视图:两个表都需要具有相同的名称吗? - MySQL DB views: Do both tables need to have the same name? 使用Solr,我还需要一个SQL数据库吗? - With Solr, Do I Need A SQL db as well? 我需要在prestashop中关闭数据库会话吗 - do I Need to close db session in prestashop 我可以从.sql创建初始CodeIgniter数据库迁移吗? - Can I create an initial CodeIgniter db migration from .sql? 如果我正在与远程mysql数据库建立安全连接,是否需要在两台服务器上都有证书 - Do I need a certificate on both servers if I'm making a secure connection to a remote mysql db
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM