I alway get this error, even I put default value on the avg_winning_trade:
django.db.utils.IntegrityError: null value in column "avg_winning_trade" of relation "trading_summary" violates not-null constraint
DETAIL: Failing row contains (43897354-d89b-4014-a607-a0e6ee423b52, 1, 2023-02-05 11:09:56.727199 00, null, 1, 19, 1, 0.00, null, -1.01, -1.01, 0, 0, 0.00, 0%, 0.00).
The second null value is avg_winning_trade who cause the error here, I don't know why it is null here
this is my model
class Summary(
ActivatorModel,
Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, null=True, blank=True)
starting_balance = models.DecimalField(default=0, max_digits=10, decimal_places=2)
total_number_of_trades = models.PositiveIntegerField(default=0)
total_number_of_winning_trades = models.PositiveIntegerField(default=0)
total_number_of_losing_trades = models.PositiveIntegerField(default=0)
total_number_of_be_trade = models.PositiveIntegerField(default=0)
largest_winning_trade = models.DecimalField(default=0, max_digits=10, decimal_places=2)
largest_losing_trade = models.DecimalField(default=0, max_digits=10, decimal_places=2)
avg_winning_trade = models.DecimalField(default=0, max_digits=10, decimal_places=2)
avg_losing_trade = models.DecimalField(default=0, max_digits=10, decimal_places=2)
total_trade_costs = models.DecimalField(default=0, max_digits=10, decimal_places=2)
trade_win_rate = models.CharField(max_length=10)
This is the table
Column | Type | Collation | Nullable | Default | Storage | Compression | Stats target | Description
-------------------------------- -------------------------- ----------- ---------- --------- ---------- ------------- -------------- -------------
id | uuid | | not null | | plain | | |
status | integer | | not null | | plain | | |
activate_date | timestamp with time zone | | | | plain | | |
deactivate_date | timestamp with time zone | | | | plain | | |
total_number_of_trades | integer | | not null | | plain | | |
user_id | integer | | | | plain | | |
total_number_of_winning_trades | integer | | not null | | plain | | |
avg_losing_trade | numeric(10,2) | | not null | | main | | |
avg_winning_trade | numeric(10,2) | | not null | | main | | |
largest_losing_trade | numeric(10,2) | | not null | | main | | |
largest_winning_trade | numeric(10,2) | | not null | | main | | |
total_number_of_be_trade | integer | | not null | | plain | | |
total_number_of_losing_trades | integer | | not null | | plain | | |
total_trade_costs | numeric(10,2) | | not null | | main | | |
trade_win_rate | character varying(10) | | not null | | extended | | |
starting_balance | numeric(10,2) | | not null | | main | | |
CodePudding user response:
avg_winning_trade field value should not be null.
CodePudding user response:
my Bad, I think I figured it myself. avg_winning_trade has 0 value by default but, In my testing I was sending null value to It. Since there was not winning trade.