doesn't have a default value Galera estou precisando de um help seguinte quando vou salvar so fica dando esta msg " SQLSTATE[HY000]: General error: 1364 Field 'descricao' doesn't have a default value " ja revisei o código todo segue abaixo: PreventivaFormView.php ...
RR
doesn't have a default value  
Galera estou precisando de um help seguinte quando vou salvar so fica dando esta msg " SQLSTATE[HY000]: General error: 1364 Field 'descricao' doesn't have a default value " ja revisei o código todo segue abaixo:

PreventivaFormView.php

 
  1. <?php
  2. /**
  3. * PreventivaFormView Registration
  4. * @author <your name here>
  5. */
  6. class PreventivaFormView extends TPage
  7. {
  8. protected $form; // form
  9. use Adianti\Base\AdiantiStandardFormTrait; // Standard form methods
  10. /**
  11. * Class constructor
  12. * Creates the page and the registration form
  13. */
  14. function __construct()
  15. {
  16. parent::__construct();
  17. $this->setDatabase('sample'); // defines the database
  18. $this->setActiveRecord('Preventivas'); // defines the active record
  19. // creates the form
  20. $this->form = new BootstrapFormBuilder('form_Preventivas');
  21. $this->form->setFormTitle('Preventivas');
  22. // create the form fields
  23. $id_preventiva = new THidden('id_preventiva');
  24. $descricao = new TEntry('descricao');
  25. // add the fields
  26. $this->form->addFields( [ new TLabel('Id Preventiva') ], [ $id_preventiva ] );
  27. $this->form->addFields( [ new TLabel('Descricao') ], [ $descricao ] );
  28. // set sizes
  29. $id_preventiva->setSize('100%');
  30. $descricao->setSize('100%');
  31. if (!empty($id_preventiva))
  32. {
  33. $id_preventiva->setEditable(FALSE);
  34. }
  35. /** samples
  36. $fieldX->addValidation( 'Field X', new TRequiredValidator ); // add validation
  37. $fieldX->setSize( '100%' ); // set size
  38. **/
  39. // create the form actions
  40. $btn = $this->form->addAction(_t('Save'), new TAction([$this, 'onSave']), 'fa:floppy-o');
  41. $btn->class = 'btn btn-sm btn-primary';
  42. $this->form->addAction(_t('New'), new TAction([$this, 'onEdit']), 'fa:eraser red');
  43. // vertical box container
  44. $container = new TVBox;
  45. $container->style = 'width: 90%';
  46. // $container->add(new TXMLBreadCrumb('menu.xml', __CLASS__));
  47. $container->add($this->form);
  48. parent::add($container);
  49. }
  50. }
  51. Preventivas.class.php:
 
  1. <?php
  2. /**
  3. * Customer Active Record
  4. * @author Raphael Mohandas
  5. */
  6. class Preventivas extends TRecord
  7. {
  8. const TABLENAME = 'preventivas';
  9. const PRIMARYKEY= 'id_preventiva';
  10. const IDPOLICY = 'max'; // {max, serial}
  11. public function __construct($id_preventiva = NULL)
  12. {
  13. parent::__construct($id_preventiva);
  14. parent::addAttribute('descricao');
  15. }
  16. }
  17. ?>


SQL:

CREATE TABLE sistema.preventivas (
id_preventiva int(11) NOT NULL AUTO_INCREMENT,
descricao varchar(150) CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,
PRIMARY KEY (id_preventiva)
)
ENGINE = INNODB
AUTO_INCREMENT = 17
AVG_ROW_LENGTH = 16384
CHARACTER SET latin1
COLLATE latin1_swedish_ci
ROW_FORMAT = DYNAMIC;

Curso Dominando o Adianti Framework

O material mais completo de treinamento do Framework.
Curso em vídeo aulas + Livro completo + Códigos fontes do projeto ERPHouse.
Conteúdo Atualizado!


Dominando o Adianti Framework Quero me inscrever agora!

Comentários (3)


NR

Essa mensagem ocorre quando se tenta realizar um insert/update e um campo not null não é preenchido. Tem certeza que o model está apontando para a tabela correta? Pois no sql o nome está "sistema.preventivas" e no model está somente "preventivas"

Se isso estiver certo, tente habilitar os logs de sql para analisar
RR

Não isso faz parte do sistema que faço conexão sql com o banco ele demonstra desta forma mesmo sistema.preventivas sistema e meu bd preventiva e a tabela.
NR

Nesse caso copie a função onSave pra dentro da sua classe e verifique o sql gerado:
 
  1. <?php
  2. TTransaction::setLogger(new TLoggerSTD); //isso vai exibir o sql em tela
  3. ?>