catchyourwaves
catchyourwaves

Reputation: 1

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.

Upvotes: 0

Views: 1430

Answers (3)

Alfonso Elsea
Alfonso Elsea

Reputation: 1

Maybe you can use the method add_to_class in this way:

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

Upvotes: 0

duffymo
duffymo

Reputation: 308898

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.

Upvotes: 1

pasamelo
pasamelo

Reputation: 1

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.

Upvotes: 0

Related Questions