How to change db table name (Different db table name than entitys name)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rautekuvchvat
    Junior Member
    • Jan 2023
    • 6

    How to change db table name (Different db table name than entitys name)

    Hi!

    I need to have different database table names for entities. For example:

    I have entity Order. The table in mysql is named 'order'. But i need to change the name of db table for example to 'order_list'.

    Where can i edit creating and reading table names?

    I've been searching that for hours, i found that in application/Espo/Core/Utils/Database/Schema/Converter.php I can set $tableName to something and that creates the tables name in DB. But thats not enough, because, when i load the page in CRM with this entity, it says Error 500 ERROR: (42S02) SQLSTATE[42S02]: Base table or view not found: 1146 Table 'blahblahblah' doesn't exist.

    Please help me! I love this system so much, I'm learning it, but i cant figure that out. Thank you!
  • rautekuvchvat
    Junior Member
    • Jan 2023
    • 6

    #2
    yuri I havent found any topic on forum talking about that, I understand that the ORM part of the system might be one of the most complicated to understand, can you please give me some hint? Is it even possible to change the table name in db and the entity still use this table? Thank you very much

    Comment

    • shalmaxb
      Senior Member
      • Mar 2015
      • 1608

      #3
      Hi, could you reveal why you would do that? perhaps this would shed a little light on it to find a solution.
      Why did you not name the entity right away order list?

      Comment

      • rautekuvchvat
        Junior Member
        • Jan 2023
        • 6

        #4
        @shalmaxb​ Im using EspoCRM for my Bachelor thesis to develop system, which will replace current system on our faculty. Their old system uses database and they want my system to have the same table names as theirs. They cant change the database (or dont want to), because the database is used by some other systems. I hope this make sense for you. I didnt name entities like that before because I didnt know that before, I was told to do that before. Now the possibility is to change somehow entity names (is there any command for that?) or find a way to edit dabatase table names, as I stated in my first question.. And also.. I can have entity "EquipmentClass" but they demand to name tables in plural like "equipment_classes". Its little bit weird, but a good opportunity to understand ORM more in EspoCRM i guess.. Thank you for your answer
        Last edited by rautekuvchvat; 01-09-2023, 02:18 PM.

        Comment


        • rabii
          rabii commented
          Editing a comment
          I think best way is to rename entities to whatever names in the database tables. check out what each database table's name and try to rename your custom entity to match the table name. check out this command might help https://github.com/espocrm/espocrm/issues/2318
          Last edited by rabii; 01-09-2023, 02:41 PM.
      • rautekuvchvat
        Junior Member
        • Jan 2023
        • 6

        #5
        rabii Thank you very much, I will try this command. Out if interest, do you know if editing ORM for that reasons would be an "overkill"? I was trying to understand if its possible to do it or if its so complicated that its not worth it.

        Comment


        • rabii
          rabii commented
          Editing a comment
          it is much complex to edit the ORM and also will not be upgrade safe so i suggest you just rename your custom entities using the command (please note that the command would only work on custom entities and not core entities).
      Working...