使用Doctrine2和Symfony2删除表 [英] Deleting table using Doctrine2 and Symfony2

查看:81
本文介绍了使用Doctrine2和Symfony2删除表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Doctrine2和Symfony2删除表?我已经生成实体和更新的模式,现在我想删除这个结构。

How can I delete table using Doctrine2 and Symfony2? I've generated entities and updated schema, now I want to delete this structure.

推荐答案

不知道我是否正确理解你的问题。你删除了一个实体,并想从数据库中删除其生成的表?如果是这样:

Not sure if I understood your question correctly. You deleted an entity and want to delete also its generated table from database? If so:

你不能这样做,因为Doctrine2只关心它知道的表 - 这意味着由Entities表示的表。由于您从应用程序中删除了一些实体,所以Doctrine不再认为该表属于您的应用程序。在同一数据库中存在不同应用程序的不同表格的情况。如果教义删除他们只是因为它不知道任何关于它们是没有意义的。这将是种族主义...但是反对表。

You can't do it, because Doctrine2 only cares about tables it knows - that means the ones that are represented by Entities. Since you deleted some Entity from your application, Doctrine no longer thinks the table belongs to your application. There are situations when there are different tables of different applications in the same database. It wouldn't make sense if Doctrine deleted them just because it doesn't know anything about them. It would be racist... but against tables.

如果你只想以编程方式删除表,可以使用原始查询。据我所知,Doctrine没有任何方法来放下桌子。或者作为替代,您可以手动执行。

If you just want to drop tables programmatically, you can use raw query. As far as I know, Doctrine doesn't have any method for dropping tables. Or as an alternative, you can do it by hand.

这篇关于使用Doctrine2和Symfony2删除表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆