简体   繁体   中英

Adding new field to an existing database

Can anybody help me with adding new column fields into the database. i have a form where i can add new trainings and another form that has a table. The problem is the new trainings i will add should save to the database as a new field. And the new field i will add will also be visible to the table.

Please i really need your help.

This is a classic mistake that cannot scale. It's a problem with your schema design.

You should not have to update your schema every time you add a new training. You need a one-to-many relationship where you add new training by INSERTing a new row.

Have a parent table for the form with the HTML table and add a child table with a foreign key to the parent for the form with the new training to INSERT.

Maybe you should consider your application architecture so that you don't have to perform structure changes in your database at runtime.

If it's unavoidable you could always use "ALTER TABLE" sentences so that you can add new fields, indexes, or whatever.

也许您可以通过这种方式使用 add_to_class 方法:

YourModel.add_to_class("fieldname",models.CharField(max_length=20,blank=True, null=True))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM